私のアプリでは、Amazonの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];
}
これを行う方法はありますか?
ありがとう、tryRotationToDeviceOrientationはトリックを行います。 – dysfunction