イベントは次のとおりです。
- (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
コンテンツは横向きになります。どうすればこれを修正できますか?