为此,我在AppDelegate中实现了这个功能.
-(UIInterfaceOrIEntationMask)application:(UIApplication *)application supportedInterfaceOrIEntationsForWindow:(UIWindow *)window{ return self.orIEntation;}
在AppDelegate.h中,方向是:
@property (nonatomic,assign) UIInterfaceOrIEntationMask orIEntation;
在我需要横向的UIVIEwcontroller中.我放置这个代码
-(voID)vIEwWillAppear:(BOol)animated{ self.appDelegate.orIEntation = UIInterfaceOrIEntationMaskLandscape;}
和
-(voID)vIEwWilldisappear:(BOol)animated{ self.appDelegate.orIEntation = UIInterfaceOrIEntationMaskPortrait;}
但是,当我去’LandscapeVIEwController’它工作正常,我回去,它工作正常,我再次去’LandscapeVIEwController’它确定,然后当我回来时,supportedInterfaceOrIEntationsForWindow方法停止调用.有什么理由吗?或者我在做一些奇怪的事情?
解决方法 如果您正在使用UITabbarController为UITabbarController创建一个自定义类并将此代码放在那里-(UIInterfaceOrIEntationMask) supportedInterfaceOrIEntations{ return UIInterfaceOrIEntationMaskPortrait;}
并根据您的需要将其放置在视图控制器中.
将此代码放在appDelegate中
-(UIInterfaceOrIEntationMask)application:(UIApplication *)application supportedInterfaceOrIEntationsForWindow:(UIWindow *)window{ return UIInterfaceOrIEntationMaskPortrait | UIInterfaceOrIEntationMaskLandscapeleft | UIInterfaceOrIEntationMaskLandscapeRight; ID rootVIEwController = [self topVIEwControllerWithRootVIEwController:window.rootVIEwController]; if (rootVIEwController != nil) { if ([rootVIEwController respondsToSelector:@selector(canRotate)]) { return UIInterfaceOrIEntationMaskLandscape; } } return UIInterfaceOrIEntationMaskPortrait;}-(UIVIEwController*) topVIEwControllerWithRootVIEwController:(ID)rootVIEwController{ if (rootVIEwController == nil) { return nil; } if ([rootVIEwController isKindOfClass:[UITabbarController class]]) { UITabbarController *selectedTabbarController = rootVIEwController; return [self topVIEwControllerWithRootVIEwController:selectedTabbarController.selectedVIEwController]; } else if ([rootVIEwController isKindOfClass:[UINavigationController class]]) { UINavigationController *selectednavController = rootVIEwController; return [self topVIEwControllerWithRootVIEwController:selectednavController.visibleVIEwController]; } else { UIVIEwController *selectedVIEwController = rootVIEwController; if (selectedVIEwController.presentedVIEwController != nil) { return [self topVIEwControllerWithRootVIEwController:selectedVIEwController.presentedVIEwController]; } } return rootVIEwController;}
并将其放在视图控制器中
-(voID)canRotate{}总结
以上是内存溢出为你收集整理的iOS9 supportedInterfaceOrientationsForWindow停止调用全部内容,希望文章能够帮你解决iOS9 supportedInterfaceOrientationsForWindow停止调用所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)