2016-09-07 9 views
0

私はこの質問が数回答えられたかもしれないことは知っていますが、文字通りStackOverflowで見つけられる可能性のあるものをすべて試しました。プログラムでUIInterfaceOrientationMaskLandscapeLeftにビューのサイズを変更

基本的に、私はそうのように初期化するカスタムUIViewのクラスがあります。そして、

MyUIView *test = [[MyUIView alloc] initWithFrame:self.view.bounds]; 

を、私はNSTimerこの呼び出しで5秒でオフに行くようにスケジュールしている:どの基本的に

AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate]; 

    if (!self.isRotated) { 
     self.isRotated = YES; 
     appDelegate.allowLandscape = YES; 
     [[UIDevice currentDevice] setValue:[NSNumber numberWithInteger: UIInterfaceOrientationLandscapeLeft] forKey:@"orientation"]; 
    }else{ 
     self.isRotated = NO; 
     appDelegate.allowLandscape = NO; 
     [[UIDevice currentDevice] setValue:[NSNumber numberWithInteger: UIInterfaceOrientationPortrait] forKey:@"orientation"]; 
    } 

い:

-(UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{ 
    if (self.allowLandscape) { 
     return UIInterfaceOrientationMaskLandscapeLeft; 
    }else{ 
     return UIInterfaceOrientationMaskPortrait; 
    } 
} 

そして私はちょうどにself.allowLandscapeを設定した場合、それが正常に動作します方法の。しかし、5秒後にNSTimerメソッドを呼び出すと、UIViewはLandscapeLeftに変換されません。

私はおそらく制約を使ってこの問題を解決できましたが、このプロジェクトではプログラマチックサイズのみを使用しています。

答えて

0

私はそうのようAutoresizingMasksを使用することをお勧め:

view.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight; 

これは、スーパークラスに応じて自動的にビューのサイズを変更します。

+0

ちょうど試してみましたが、何もしませんでした.. –

関連する問題