我有UIScrollView
纵向模式的xib文件。当我运行应用程序并将设备旋转到横向模式时,我看到了UIScrollView
. UIScrollView
底部内部的一半控件无法访问。没有任何可见的滚动条。
如何防止更改UIScrollView
设备方向后的垂直尺寸变化?
非常感谢您的帮助!
我有UIScrollView
纵向模式的xib文件。当我运行应用程序并将设备旋转到横向模式时,我看到了UIScrollView
. UIScrollView
底部内部的一半控件无法访问。没有任何可见的滚动条。
如何防止更改UIScrollView
设备方向后的垂直尺寸变化?
非常感谢您的帮助!
更改 UIScrollView 的框架
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation;
根据设备旋转。
shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if(interfaceOrientation == UIInterfaceOrientationPortrait)
{
//set frame for scroll in portrait mode
}
else if(interfaceOrientation == UIInterfaceOrientationLandscapeLeft)
{
//set frame for landscape
}
}
编辑:选择您的 UIScrollView 并像这样更改滚动视图的 autoresize 属性。
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation;
{
//change sub view of scrollview accordingly to orientation
if(UIInterfaceOrientationIsPortrait(interfaceOrientation))
yourScrollView.frame = CGRectMake(0,0,320,460);
yourScrollView.contentSize = CGSizeMake(320,460);//change accordingly
else
yourScrollView.frame = CGRectMake(0,0,480,300);
yourScrollView.contentSize = CGSizeMake(480,460); //change accordingly
return YES;
}
选择您的 UIScrollView,然后从属性中单击大小检查器并更改视图的 autoresize 属性。
使用代码:
scrollView.contentSize = CGSizeMake(宽度, 高度);