Objective c 旋转时调整大小
我试图在一个页面上放置一个UIScroll视图,该页面填充该页面的边缘减去10px的边距。这是我做的。但是,我还希望UIScrollView在设备旋转时调整大小,保持10px的边距。到目前为止,我的代码是:Objective c 旋转时调整大小,objective-c,rotation,Objective C,Rotation,我试图在一个页面上放置一个UIScroll视图,该页面填充该页面的边缘减去10px的边距。这是我做的。但是,我还希望UIScrollView在设备旋转时调整大小,保持10px的边距。到目前为止,我的代码是: // Get the screen dimensions, considering the status bar scrollWidth = self.getScreenSize.width // evaluates to 1004 in landscape & 748 in p
// Get the screen dimensions, considering the status bar
scrollWidth = self.getScreenSize.width // evaluates to 1004 in landscape & 748 in portrait
scrollHeight = self.getScreenSize.height // evaluates to 728 in landscape & 984 in portrait
scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(10,10,scrollWidth,scrollHeight)];
[scrollView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];
... other stuff to load scrollview content ...
[self.view addSubview:scrollView];
当我启动应用程序时,scrollView比页面宽,无论我以哪个方向启动它。删除[scrollView setAutoresizingMask..行可使scrollView完美匹配,但不会对设备旋转做出反应
我做错了什么?使用
shouldAutorotateToInterfaceOrientation
检测屏幕何时旋转,然后更改滚动视图的帧:
CGRect frame = scrollView.frame
//Change frame
scrollView.frame = frame;
如果您的目标是6.0或更高版本,请使用自动布局/约束。这比处理帧、边界和中心要容易得多。只需为不同的3旋转位置设置不同的3帧,然后将条件放入其中,检查当前旋转状态,并根据该设置刚刚手动更改的滚动的特定帧scrollview的框架。谢谢。看起来shouldAutorotateToInterfaceOrientation可能不受欢迎,但shouldAutorotate做到了这一点。