2

ターゲットの向きに基づいて、回転できるようにしたい

[[UIDevice currentDevice] orientation] 

ただし、上記のコードをshouldRotateで使用すると、ターゲットの方向ではなく、現在の(古い)方向が保持されます。

- (BOOL) shouldAutorotate {

    return YES;
}
4

3 に答える 3

0

わかりました。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
}
于 2012-10-12T11:21:05.630 に答える
0
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration

この方法でうまくいくはずです。toInterfaceOrientationは、ターゲットの方向を保持します。

于 2012-10-12T14:01:56.310 に答える
-1

はいを返すことは別として

-(BOOL)shouldAutorotate
{
return YES;
}

実装する必要があります

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscape;
}

利用可能なさまざまなマスクは次のとおりです。

UIInterfaceOrientationMaskPortrait
UIInterfaceOrientationMaskLandscapeLeft
UIInterfaceOrientationMaskLandscapeRight
UIInterfaceOrientationMaskPortraitUpsideDown
UIInterfaceOrientationMaskLandscape
UIInterfaceOrientationMaskAll
UIInterfaceOrientationMaskAllButUpsideDown

あなたも見たいかもしれません:

https://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instm/UIViewController/supportedInterfaceOrientations

于 2012-10-03T09:54:14.703 に答える