设备方向更改后如何防止UIScrollView的大小?

时间:2012-10-11 05:37:10

标签: iphone ios uiscrollview orientation

enter image description here

我在纵向模式下的xib文件上有UIScrollView。当我运行应用程序并将设备旋转到横向模式时,我会看到UIScrollView的新界限。底部UIScrollView内的一半控件无法访问。没有任何滚动条可见。

如何防止在更改设备方向后更改UIScrollView的垂直尺寸?

enter image description here enter image description here

非常感谢您的帮助!

5 个答案:

答案 0 :(得分:0)

中更改UIScrollView的框架
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation;

根据设备轮换。

答案 1 :(得分:0)

 shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
      if(interfaceOrientation == UIInterfaceOrientationPortrait)
    {
         //set frame for scroll in portrait mode
    }
    else  if(interfaceOrientation == UIInterfaceOrientationLandscapeLeft)
    {
      //set frame for landscape
    }

   }

答案 2 :(得分:0)

编辑:选择您的UIScrollView并更改滚动视图的autoresize属性,如下所示。

enter image description here

 - (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;
 }

答案 3 :(得分:0)

选择您的UIScrollView,然后从属性中单击大小检查器并更改视图的autoresize属性。

see image

答案 4 :(得分:0)

  1. 设置参考插座
  2. 使用代码:

    scrollView.contentSize = CGSizeMake(width,height);