现在,当我旋转设备时,我不希望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?
谢谢你的帮助!
解决方法 尝试使用UIDevice实例来检测设备物理方向的变化.要开始接收通知,您可以使用类似的内容(例如,在vIEwWillAppear:方法中):
- (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];}
这是deviceDIDRotate函数的一个例子:
- (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中定义所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)