【问题标题】:How to prevent size of UIScrollView after device orientation is changed?更改设备方向后如何防止 UIScrollView 的大小?
【发布时间】:2012-10-24 23:39:19
【问题描述】:

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

如何防止UIScrollView在设备方向改变后垂直大小发生变化?

非常感谢您的帮助!

【问题讨论】:

  • 你需要为scrollview设置contentSize。检查是否设置正确。滚动条基于此显示。
  • 我知道 - 但它没有帮助:(
  • 您能否发布更多详细信息,例如您尝试做什么以及确切的结果是什么?是否根本不接受您在 shouldAutorotateToInterfaceOrientation 中设置的框架?还是方法本身没有被调用?

标签: iphone ios uiscrollview orientation


【解决方案1】:

改变UIScrollView的框架

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation;

根据设备旋转。

【讨论】:

    【解决方案2】:
     shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
        {
          if(interfaceOrientation == UIInterfaceOrientationPortrait)
        {
             //set frame for scroll in portrait mode
        }
        else  if(interfaceOrientation == UIInterfaceOrientationLandscapeLeft)
        {
          //set frame for landscape
        }
    
       }
    

    【讨论】:

      【解决方案3】:

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

      【讨论】:

      • 这对我有用,尝试不同的 autoresize 属性设置。
      【解决方案4】:

      编辑: 选择您的 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;
       }
      

      【讨论】:

        【解决方案5】:
        1. 设置参考插座
        2. 使用代码:

          scrollView.contentSize = CGSizeMake(width, height);

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2021-06-05
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2018-08-31
          相关资源
          最近更新 更多