El *_*ino 4 orientation uiinterfaceorientation ios6
只需将iOS 5应用程序更新到iOS 6,当然偶然发现了界面问题.我现在已经知道事情发生了变化,我甚至知道发生了什么变化,但我似乎无法自己管理.
我的应用程序包含几个viewcontrollers,它们被推送到一个navigationcontroller.所有的viewcontrollers都应该是横向的,除了一个应该是纵向的.在iOS 5中,一切工作正常,但现在纵向模式下的一个控制器也以横向模式显示,当然也会失真.
我的iOS 5代码看起来像这样:
Viewcontroller在横向模式下:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
return (interfaceOrientation==UIInterfaceOrientationLandscapeLeft) || (interfaceOrientation==UIInterfaceOrientationLandscapeRight);
}
Run Code Online (Sandbox Code Playgroud)
Viewcontroller处于纵向模式:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
return (interfaceOrientation==UIInterfaceOrientationPortrait) || (interfaceOrientation==UIInterfaceOrientationPortraitUpsideDown);
}
Run Code Online (Sandbox Code Playgroud)
现在我发现了我实施的iOS 6中的变化
AppDelegate :(允许所有方向,如在plist中)
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
return UIInterfaceOrientationMaskLandscapeLeft|UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
}
Run Code Online (Sandbox Code Playgroud)
横向模式下的Viewcontroller :(将方向限制为横向模式)
- (NSUInteger) supportedInterfaceOrientations{
return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight
}
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
}
- (BOOL)shouldAutorotate{
return YES;
}
Run Code Online (Sandbox Code Playgroud)
纵向模式下的Viewcontroller :(将方向限制为纵向模式)
- (NSUInteger) supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
}
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationPortrait | UIInterfaceOrientationPortraitUpsideDown;
}
- (BOOL)shouldAutorotate {
return YES;
}
Run Code Online (Sandbox Code Playgroud)
从我的理解,这应该工作,但事实是它比以前更少工作.首先,横向模式视图控制器不会保持横向模式,它们可以在所有方向上自由旋转,这当然不是我想要的.其次,纵向模式下的viewcontroller会崩溃
Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation', reason: 'preferredInterfaceOrientationForPresentation must return a supported interface orientation!'
Run Code Online (Sandbox Code Playgroud)
经过一些试验和错误后,我似乎只能通过plist文件/ appdelegate将所有控制器锁定到横向模式,这当然会强制纵向模式控制器进入横向模式.另一方面,我可以设置纵向模式控制器处于正确的方向,但这也将横向模式控制器旋转为纵向模式.我似乎无法兼顾两者.
有任何想法吗?
好的,我修好了.
我为UINavigationController创建了一个类别
@implementation UINavigationController (Rotation_IOS6)
-(BOOL)shouldAutorotate
{
return [self.topViewController shouldAutorotate];
}
-(NSUInteger)supportedInterfaceOrientations
{
return [self.topViewController supportedInterfaceOrientations];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return [self.topViewController preferredInterfaceOrientationForPresentation];
}
@end
Run Code Online (Sandbox Code Playgroud)
将视图控制器的值转发到navigationcontroller ...
我还必须用presentViewController替换presentModalViewController,因为第一个现在已弃用.
顺便说一句,是的,我的appdelegate中有一个拼写错误...这是正确的.
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
return UIInterfaceOrientationMaskLandscapeLeft|UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskPortrait|UIInterfaceOrientationMaskPortraitUpsideDown;
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
6273 次 |
最近记录: |