iOS 检测设备旋转状态

在plist中可以设置你的app支持几种方向,设置以后在程序中可以响应到这类方向调整。不过这种方式必须设置支持旋转 并且子controller想要旋转必须它的父controller也必须支持旋转。 在项目开发过程中经常会遇到有些页面要支持横屏可它的父controller不要支持横屏,这种情况很难处理


一下这种方式可以一试

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
    [[NSNotificationCenter defaultCenter]
     addObserver:(id)(iOSRotationNotificaiton::getInstance()->m_delegate) selector:@selector(orientationChanged:)
     name:UIDeviceOrientationDidChangeNotification
     object:[UIDevice currentDevice]];

在需要支持旋转的controller中加入观察  

发布了17 篇原创文章 · 获赞 6 · 访问量 7万+

猜你喜欢

转载自blog.csdn.net/jacky_jin/article/details/47107643
今日推荐