iOS9 supportedInterfaceOrientationsForWindow停止调用

概述我希望在横向模式下显示1或2个UIView控制器,而在Portrait中显示其他人. 为此,我在AppDelegate中实现了这个功能. -(UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{ 我希望在横向模式下显示1或2个UIVIEw控制器,而在Portrait中显示其他人.
为此,我在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停止调用所遇到的程序开发问题。

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

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1067263.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存