大佬教程收集整理的这篇文章主要介绍了ios6 – 检测UIViewController上的接口旋转,即使未在 – (NSUInteger)supportedInterfaceOrientations中定义,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
现在,当我旋转设备时,我不希望viewController旋转,而只是UIImageViews.换句话说,底部的工具栏将位于左侧(或右侧),但imageViews将正确旋转.
- (BOOL)shouldAutoRotate { return YES; }
结合
- (NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskPorTrait; }
和
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { // rotate the image views here }
设备上的任何旋转都不会被执行,因为只支持一个接口方向(UIInterfaceOrientationMaskPorTrait).但是当我在supportedInterfaceOrientations方法中添加另一个接口方向时,视图控制器也会旋转.
即使只支持一个方向,如何检测视图控制器的旋转?或者是否有另一种可能性根据不断变化的设备方向旋转UIViews?
谢谢你的帮助!
- (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; //No reason to ask Nsnotification because it many cases `userInfo` equals to //@{UIDeviceOrientationRotateAnimatedUserInfoKey = 1;} [[NsnotificationCenter defaultCenter] addObserver:self SELEctor:@SELEctor(deviceDidRotatE) name:@UIDeviceOrientationDidChangeNotification object:nil]; }
要取消注册接收设备旋转事件,请使用此选项(例如,在viewWillDisappear中):
- (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications]; [[NsnotificationCenter defaultCenter] removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil]; }
- (void)deviceDidRotate { UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation]; switch (orientation) { case UIDeviceOrientationPorTrait: case UIDeviceOrientationPorTraitUpsideDown: // do something for porTrait orientation break; case UIDeviceOrientationLandscapeLeft: case UIDeviceOrientationLandscapeRight: // do something for landscape orientation break; default: break; } }
以上是大佬教程为你收集整理的ios6 – 检测UIViewController上的接口旋转,即使未在 – (NSUInteger)supportedInterfaceOrientations中定义全部内容,希望文章能够帮你解决ios6 – 检测UIViewController上的接口旋转,即使未在 – (NSUInteger)supportedInterfaceOrientations中定义所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。