【问题标题】:Handling iPhone 3.5inch and IPhone 4inch display (UIScrollView)处理 iPhone 3.5 英寸和 iPhone 4 英寸显示屏 (UIScrollView)
【发布时间】:2013-10-10 10:42:10
【问题描述】:

我在设计适合 3.5 英寸 iPhone 和 5 英寸 iPhone(模拟器)的布局时遇到了困难。我检查了自动布局,所有布局都很完美。但是我现在需要使用 UIScrollView,因此需要取消选中自动布局才能使用。

此外,当使用 iPhone 4 英寸显示屏查看布局时,它会在 UIScrollView 的顶部增加大约 60 像素。

有没有更好的方法来做到这一点(设置滚动视图而不取消选择自动布局)?所以我可以支持 iPhone 4。

//to set up the scrollview
[self.scrollView setScrollEnabled:YES];
[self.scrollView setContentSize:CGSizeMake(320, 800)];

但是在我取消选中自动布局之前它不会滚动。有没有更好的方法来做到这一点?

【问题讨论】:

  • 请把您的问题截图,以便更好地理解。
  • UIScrollView, and therefore need to uncheck auto-layout to use 为什么会这样?
  • @ArkadiuszHolko 由于某种原因,如果不取消选中自动布局,滚动视图将不会滚动。但是我可能做错了。
  • @Gman 添加更多代码并将屏幕截图也放入以了解更多信息......
  • @Gman 没有其他代码,我使用故事板连接滚动视图并将其高度设置为大于视图本身,即。 800 小时。

标签: iphone ios objective-c uiscrollview


【解决方案1】:

尝试自动调整大小,

 self.scrollView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin);

【讨论】:

    【解决方案2】:

    试试这个(它解决了我的问题):

    scrollView addConstraint:[NSLayoutConstraint constraintWithItem:lastSubView
                                             attribute:NSLayoutAttributeRight
                                             relatedBy:NSLayoutRelationEqual
                                                toItem:scrollView
                                             attribute:NSLayoutAttributeRight
                                            multiplier:1.0
                                              constant:0]];
    

    参考:UIScrollView doesn't use autolayout constraints

    【讨论】:

      【解决方案3】:

      UIScrollView 使用自动布局时略有不同。你需要做一些修改。你的回答是here

      【讨论】:

      • 感谢您的评论,我尝试实施建议的内容,但我觉得我有点迷失了,我创建了一个子视图并将其添加为滚动视图,而不是添加 uiElements [scrollView addConstraint:[NSLayoutConstraint constraintWithItem:lastSubView attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:scrollView attribute:NSLayoutAttributeRight multiplier:1.0 constant:0]];
      • 现在你在使用自动布局吗?检查自动布局?如果您使用自动布局,您是否添加了translatesAutoresizingMaskIntoConstraints = NO;
      • 我在使用 AutoLayout 但我没有使用translatesAutoresizingMaskIntoConstraints = NO;,这样可以吗?
      【解决方案4】:

      您可以对您的UIScrollView frame 执行类似操作。按照下面的 CGRect 将框架分配给滚动视图。

      CGRect rect=[[UIScreen mainScreen] bounds];
      

      希望,这对你有用。

      【讨论】:

      • 您能进一步解释一下吗?
      猜你喜欢
      • 2014-03-30
      • 1970-01-01
      • 1970-01-01
      • 2012-09-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-29
      • 1970-01-01
      相关资源
      最近更新 更多