我有一个推动UIViewController(Child)的UINavigationController(Parent)。我知道两者都需要支持:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return YES; //(interfaceOrientation == UIInterfaceOrientationPortrait);
}
但是,我不希望父级能够旋转到横向。我该如何强制执行此操作?
更新:
我的父母已更新为:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if (interfaceOrientation != UIInterfaceOrientationLandscapeRight ||interfaceOrientation != UIInterfaceOrientationLandscapeLeft )
return NO;
else
return YES;
}
但现在孩子不会轮换。
答案 0 :(得分:1)
在您的父视图控制器中,您需要实现此功能。如果您尚未将用于父级的UINAvigationController子类化,请执行此操作并添加此方法。
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if (interfaceOrientation != UIInterfaceOrientationLandscape)
return NO;
else
return YES;
}
在子View COntroller子类中,像你一样实现方法:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return YES; //(interfaceOrientation == UIInterfaceOrientationPortrait);
}