use*_*325 5 objective-c uinavigationcontroller ios6
我正在使用iOS 6.0测试版,我的轮换不再起作用了.
我在哪里可以设置UINavigationControllers supportedOrientations?
根据这个http://news.yahoo.com/apple-ios-6-beta-3-changes-182849903.html,UINavigation 控制器不会咨询他们的孩子,以确定他们是否应该自动旋转.
我没有使用shouldAutorotateToInterfaceOrientation:因为它已被弃用.相反,我使用supportedInterfaceOrientations:和shouldAutoRotate:并且它们正常工作,直到我将ViewController放入NavigationController(作为Child).从那时起,ViewController中指定的方向不再起作用.它似乎正在使用导航控制器设置的方向(UIInterfaceOrientationMaskAllButUpsideDown)
如何为NavigationController设置InterfaceOrientations,以便我的ViewControllers被锁定为纵向方向?
我是否必须继承UINavigationController并在那里设置InterfaceOrientations?在iOS 6.0中继承UINavigationController并不是不好的做法吗?
谢谢你帮忙堆!
干杯!
如果你想再次咨询它的孩子,你可以在UINavigationController中添加一个类别
@implementation UINavigationController (Rotation_IOS6)
-(BOOL)shouldAutorotate
{
return [[self.viewControllers lastObject] shouldAutorotate];
}
-(NSUInteger)supportedInterfaceOrientations
{
return [[self.viewControllers lastObject] supportedInterfaceOrientations];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
}
@end
Run Code Online (Sandbox Code Playgroud)
小智 4
子类 UINavigationController
//OnlyPortraitNavigationController.h
@interface OnlyPortraitNavigationController : UINavigationController
Run Code Online (Sandbox Code Playgroud)
//OnlyPortraitNavigationController.m
@implementation OnlyPortraitNavigationController
- (BOOL)shouldAutorotate {
return NO;
}
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait; //for locked only Portrait
}
Run Code Online (Sandbox Code Playgroud)
使用您的肖像 ViewController 呈现新的子类 navigationController
SomeViewController *onlyPortraitVC = [[SomeViewController alloc]init];
OnlyPortraitNavigationController *portraitNav = [[OnlyPortraitNavigationController alloc]initWithRootViewController:onlyPortraitViewController];
[self presentViewController:portraitNav animated:YES completion:NULL];
Run Code Online (Sandbox Code Playgroud)
这是我的应用程序的工作希望它可以帮助你。
| 归档时间: |
|
| 查看次数: |
4042 次 |
| 最近记录: |