0

イベントは次のとおりです。

- (BOOL)shouldAutorotateToInterfaceOrientation (UIInterfaceOrientation)interfaceOrientation
{    
    [self setupScrollView];
    return YES;
}

デバイスを回転させるときはいつでも、UIScrollView中身が常に「正しい」面になるようにセットアップします。

    if ([[UIDevice currentDevice] orientation] == UIInterfaceOrientationPortrait)
    {
        self.scrollView.transform = CGAffineTransformIdentity;
    }
    else if ([[UIDevice currentDevice] orientation] == UIInterfaceOrientationPortraitUpsideDown)
    {
        self.scrollView.transform = CGAffineTransformRotate(self.scrollView.transform, M_PI);
    }
    else if ([[UIDevice currentDevice] orientation] == UIInterfaceOrientationLandscapeLeft)
    {
        self.scrollView.transform = CGAffineTransformRotate(self.scrollView.transform, -M_PI/2);
    }
    else if ([[UIDevice currentDevice] orientation] == UIInterfaceOrientationLandscapeRight)
    {
        self.scrollView.transform = CGAffineTransformRotate(self.scrollView.transform, M_PI/2);
    }

これは、デバイスが横向きから縦向き (右側が上) に回転した場合を除いて機能し、ブレークポイントshouldAutorotateToInterfaceOrientationが呼び出されていないことを確認します。そのため、デバイスを縦向きに戻すと、UIScrollViewコンテンツは横向きになります。どうすればこれを修正できますか?

4

1 に答える 1

0

上記が機能しなかった理由はまだわかりませんが、以下は機能しているようです:

- (void)viewDidLoad {
[super viewDidLoad];  

//for some reason shouldAutorotateToInterfaceOrientation isn't firing when returning to portrait so we need to register for notifications
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(setupScrollView) name:UIDeviceOrientationDidChangeNotification object:nil];
}
于 2012-07-04T21:03:35.807 に答える