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 回答