私は非常に単純なUIViewControllerを持っています。私はwillRotateToInterfaceOrientationの使い方を理解しようとしています。私のUIViewControllerは、非常に単純なviewDidLoadメソッドを持っていますiOS willRotateToInterfaceOrientation適切な使用法
-(void)viewDidLoad {
[super viewDidLoad];
theBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 48.0f)];
theBar.tintColor = [UIColor orangeColor];
UINavigationItem *item = [[UINavigationItem alloc] initWithTitle:@"The Title"];
item.hidesBackButton = YES;
[theBar pushNavigationItem:item animated:YES];
[item release];
[self.view addSubview:theBar];
}
だから、基本的に、私はちょうど私のコントローラの上部にあるUINavigationBarを持っています。それでおしまい。私は私がオンラインで見つけるものに基づいて、回転のためのいくつかのメソッドを実装し:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
-(void)willRotateToInterfaceOrientation: (UIInterfaceOrientation)orientation duration:(NSTimeInterval)duration {
if ((orientation == UIInterfaceOrientationLandscapeLeft) || (orientation == UIInterfaceOrientationLandscapeRight)) {
theBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, 640, 48)];
}
}
だから、私はポートレートモードでアプリを起動した後、私は風景モードでツイスト。そして基本的には、theBar
はまだ通常のサイズのままであり、サイズ変更されません。私はこれが愚かな質問だと確信していますが、回転機能を使用する適切な方法は何ですか?アプリを横長モードで起動しても機能するようにしたいと思います。 UIViewControllerが最初に起動したときにコンポーネントを初期化する最良の方法は何ですか?私は両方向のサポートが必要であることを念頭に置いてください。また、期間全体を通して方向の変化に基づいてすべてのサイズを変更できますのUIViewControllerの生活ですか?ありがとう!
はあなたが自動サイズ変更マスクを試したことがありますか? – Pripyat
これは何ですか?私に例を教えてもらえますか? – CodeGuy