dys*_*ion 5 iphone objective-c ios ios5 ios6
我正在我的应用程序中实现类似于亚马逊的Kindle应用程序中的程序化旋转锁定:当设备旋转时,锁定按钮显示; 按下按钮,方向锁定到按下按钮时界面所在的方向.
解锁后,我想让界面旋转到当前的设备方向.假设你以纵向锁定旋转,将设备旋转到横向左侧,然后解锁; 我想界面然后旋转到横向左侧.这是切换锁的方法:
- (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];
}
Run Code Online (Sandbox Code Playgroud)
有什么办法吗?
关键是 1) 将当前方向保存为用户默认值,就像您正在做的那样 2) 您需要做的所有其余操作是在您想要锁定的视图控制器的重写方法中(对于 ios 6+,supportedInterfaceOrientations)。使用保存的用户默认值根据锁定与否返回您允许的方向。
然后调用attemptRotationToDeviceOrientation
告诉您的视图控制器再次调用它们的方法,并重新评估在给定设备当前旋转的情况下它们应该进行的旋转。
| 归档时间: |
|
| 查看次数: |
1725 次 |
| 最近记录: |