【发布时间】:2015-02-03 21:16:07
【问题描述】:
我在下面有这段代码,它识别设备何时改变他的方向,如果方向是横向的左或右,他又回到纵向:
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter]
addObserver:self selector:@selector(orientationChanged:)
name:UIDeviceOrientationDidChangeNotification
object:[UIDevice currentDevice]];
- (void) orientationChanged:(NSNotification *)note{
UIDevice * device = note.object;
if(device.orientation == UIDeviceOrientationLandscapeRight){
[[UIDevice currentDevice] setValue:
[NSNumber numberWithInteger: UIInterfaceOrientationPortrait]
forKey:@"orientation"];
}
if(device.orientation == UIDeviceOrientationLandscapeLeft){
[[UIDevice currentDevice] setValue:
[NSNumber numberWithInteger: UIInterfaceOrientationPortrait]
forKey:@"orientation"];
}
}
当我运行我的项目并将设备的方向更改为横向或横向时,此代码会识别并将方向更改为纵向,但如果我再次将设备旋转到横向或横向,则代码不起作用我的设备一直处于横向模式,为什么?以及如何解决这个问题?
【问题讨论】:
标签: ios objective-c uiinterfaceorientation uidevice