ターゲットの向きに基づいて、回転できるようにしたい
[[UIDevice currentDevice] orientation]
ただし、上記のコードをshouldRotateで使用すると、ターゲットの方向ではなく、現在の(古い)方向が保持されます。
- (BOOL) shouldAutorotate {
return YES;
}
わかりました。shouldAutorotateで常にYESを返し、次のようにします。
- (NSUInteger)supportedInterfaceOrientations
{
if ([UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeLeft) {
// Allow if you can
} else if ([UIDevice currentDevice].orientation == UIDeviceOrientationPortrait) {
// Allow if you can
}
// so on
}
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
この方法でうまくいくはずです。toInterfaceOrientationは、ターゲットの方向を保持します。
はいを返すことは別として
-(BOOL)shouldAutorotate
{
return YES;
}
実装する必要があります
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
利用可能なさまざまなマスクは次のとおりです。
UIInterfaceOrientationMaskPortrait
UIInterfaceOrientationMaskLandscapeLeft
UIInterfaceOrientationMaskLandscapeRight
UIInterfaceOrientationMaskPortraitUpsideDown
UIInterfaceOrientationMaskLandscape
UIInterfaceOrientationMaskAll
UIInterfaceOrientationMaskAllButUpsideDown
あなたも見たいかもしれません: