如何强制子视图横向,而不是父视图?
我有一个 UINavigationController (父级)正在推动 UIViewController (子级)。我知道两者都需要支持:
- (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;
}
但现在孩子不旋转。
I have a UINavigationController (Parent) that is pushing a UIViewController (Child). I understand that both need to support:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return YES; //(interfaceOrientation == UIInterfaceOrientationPortrait);
}
However, I don't want the parent to be able to rotate to landscape orientation. How can I enforce this?
UPDATE:
My Parent has been updated to:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if (interfaceOrientation != UIInterfaceOrientationLandscapeRight ||interfaceOrientation != UIInterfaceOrientationLandscapeLeft )
return NO;
else
return YES;
}
But now the child doesn't rotate.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在你的父视图控制器中,你需要实现这个。如果您尚未对用于父级的 UINAvigationController 进行子类化,只需执行此操作并添加此方法即可。
在子 View COntroller 子类中,像您一样实现该方法:
In your parent View Controller you will need to implement this. If you have not already subclassed the UINAvigationController you are using for the parent, just do that and add this method.
In the child View COntroller subclass, implement the method like you did: