以下是活动:
- (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
内容是侧面的。我该如何解决这个问题?
答案 0 :(得分: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];
}