iOS   发布时间:2022-03-30  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了iOS6接口方向已损坏大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
只需将iOS 5应用程序更新到iOS 6,当然偶然发现了界面问题.我现在已经知道事情发生了变化,我甚至知道发生了什么变化,但我似乎无法自己管理.

我的应用程序包含几个viewcontrollers,它们被推送到一个navigationcontroller.所有的viewcontrollers都应该是横向的,除了一个应该是纵向的.在iOS 5中,一切工作正常,但现在纵向模式下的一个控制器也以横向模式显示,当然也会失真.

我的iOS 5代码看起来像这样:

Viewcontroller在横向模式下:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
return (interfaceOrientation==UIInterfaceOrientationLandscapeLeft) || (interfaceOrientation==UIInterfaceOrientationLandscapeRight);
}

Viewcontroller处于纵向模式:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
return (interfaceOrientation==UIInterfaceOrientationPortrait) || (interfaceOrientation==UIInterfaceOrientationPortraitUpsideDown);
}

现在我发现了我实施的iOS 6中的变化

AppDelegate :(允许所有方向,如在plist中)

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
return UIInterfaceOrientationMaskLandscapeLeft|UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
}

横向模式下的Viewcontroller :(将方向限制为横向模式)

- (NSUInteger) supportedInterfaceOrientations{
return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight
}

-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
}

- (BOOL)shouldAutorotate{ 
return YES;
}

纵向模式下的Viewcontroller :(将方向限制为纵向模式)

- (NSUInteger) supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
}

-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { 
return UIInterfaceOrientationPortrait | UIInterfaceOrientationPortraitUpsideDown;
}

- (BOOL)shouldAutorotate { 
return YES;
}

从我的理解,这应该工作,但事实是它比以前更少工作.
首先,横向模式视图控制器不会保持横向模式,它们可以在所有方向上自由旋转,这当然不是我想要的.其次,纵向模式下的viewcontroller会崩溃

Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation',reason: 'preferredInterfaceOrientationForPresentation must return a supported interface orientation!'

经过一些试验和错误之后,我似乎只能通过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

将视图控制器的值转发到navigationcontroller …

我还必须用presentViewController替换presentModalViewController,因为第一个现在已弃用.

顺便说一句,是的,我的appdelegate中有一个拼写错误…这是正确的.

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
return UIInterfaceOrientationMaskLandscapeLeft|UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskPortrait|UIInterfaceOrientationMaskPortraitUpsideDown;
}

大佬总结

以上是大佬教程为你收集整理的iOS6接口方向已损坏全部内容,希望文章能够帮你解决iOS6接口方向已损坏所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: