我在我的应用程序中实现了一个类似于亚马逊Kindle应用程序中的编程旋转锁:当设备旋转时,锁按钮显示;按下按钮并且方向锁定到按下按钮时界面所在的方向。解锁编程旋转锁后强制iOS ViewController旋转到设备方向
解锁后,我想界面旋转到当前的设备方向。假设您锁定纵向旋转,将设备旋转至左侧,然后解锁;我想让界面旋转到左侧。这里是切换锁的方法:
- (IBAction)toggleRotationLock:(UIButton *)sender {
BOOL rotationLocked = [_defaults boolForKey:@"RotationLocked"];
if (rotationLocked) { //unlock rotation
[_defaults setBool:NO forKey:@"RotationLocked"];
/* force rotation to current device orientation here?
* ...
*/
} else { //lock rotation to current orientation
[_defaults setBool:YES forKey:@"RotationLocked"];
[_defaults setInteger:self.interfaceOrientation forKey:@"RotationOrientation"];
}
[_defaults synchronize];
[self setupRotationLockButton];
}
任何方式来做到这一点?
谢谢,attemptRotationToDeviceOrientation做的伎俩! – dysfunction