UIScrollView中不使用自动布局约束 [英] UIScrollView doesn't use autolayout constraints

查看:316
本文介绍了UIScrollView中不使用自动布局约束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个滚动视图和它背后的成像图,我用笔尖填充它。我使用的自动布局。我有一个底部空间,上海华和顶部空间的SuperView两个的意见。图像视图不正是我想要它做的。为iPhone 5这就是我想要的。并为其他的iPhone,它停留在屏幕的底部上方,所以正确地调整大小。滚动视图看起来正确的iPhone 5,但在其他手机它不会调整,所以它向下滚动应用程序的视图下方。我在日志中得到这些消息:

I have a scroll view and an image view behind it and I am populating it with nibs. I am using autolayout. I have a bottom space to superview and a top space to superview on both of the views. The image view does exactly what I want it to do. For iphone 5 it is where I want it. And for the other iphones, it stays above the bottom of the screen, so it resizes correctly. The scroll view looks right on the iphone 5, but on the other phones it doesn't get resized, so it scrolls down below the view of the app. I get these messages in the log:

 2012-11-21 10:42:38.576 LCHApp[12604:907] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want. 
  Try this: (1) look at each constraint and try to figure out which you don't expect;
  (2) find the code that added the unwanted constraint or constraints and fix it.
 (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer
  to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) 

"<NSLayoutConstraint:0x1d8ea080 UIScrollView:0x1d8413b0.bottom == UIImageView:0x1d892110.bottom>",
"<NSAutoresizingMaskLayoutConstraint:0x1d8cca10 h=-&- v=-&- ScheduleViewNib:0x1d853630.height == UIScrollView:0x1d8413b0.height - 386>",
"<NSLayoutConstraint:0x1d8e5340 V:[UIImageView:0x1d892110]-(64)-|   (Names: '|':ScheduleView:0x1d8efc30 )>",
"<NSAutoresizingMaskLayoutConstraint:0x1d8cf520 h=--& v=--& V:[ScheduleView:0x1d8efc30(480)]>",
"<NSLayoutConstraint:0x1d8eaed0 V:|-(45)-[UIScrollView:0x1d8413b0]   (Names: '|':ScheduleView:0x1d8efc30 )>"


 Will attempt to recover by breaking constraint 
 <NSLayoutConstraint:0x1d8ea080 UIScrollView:0x1d8413b0.bottom ==      UIImageView:0x1d892110.bottom>

我已经尝试过

[self setTranslatesAutoresizingMaskIntoConstraints:YES];

[self.myScrollView setTranslatesAutoresizingMaskIntoConstraints:YES];

从我所看到的这恰恰起飞从视图的所有限制。而且是不是我想要的。

From what I can see this just takes off all constraints from the views. And isn't what I want.

推荐答案

的UIScrollView和经销商的布局之间的关系是从汽车的布局等方面的不同。基本上,如果简单的自动布局被允许来操作,没有什么会滚动。例如,如果滚动视图的子视图被以正常的方式通过一个约束从滚动视图的顶部针扎到10点,将它完全固定有;它永远不会动,无论滚动视图是如何滚动。

The relationship between UIScrollView and auto layout is different from other aspects of auto layout. Basically, if simple auto layout were allowed to operate, nothing would scroll. For example, if a subview of the scroll view were pinned in the normal way by a constraint to 10 points from the top of the scroll view, it would be absolutely pinned there; it would never move, no matter how the scroll view were scrolled.

要解决这个问题,使用自动布局一个UIScrollView在一种全新的方式工作。因此,当你说我用的自动布局,则必须prepare的东西非常不同于之前运行。您必须使用一个单一的滚动视图子视图与 translatesAutoresizingMaskIntoConstraints = YES ,并明确内容的大小,否则一切都必须以 translatesAutoresizingMaskIntoConstraints = NO 和内容规模将隐含根据子视图的约束推断。

To solve this problem, a UIScrollView that uses autolayout operates in a completely new way. Therefore when you say "I am using autolayout" you must prepare for things to operate very differently from before. You must either use a single scroll view subview with translatesAutoresizingMaskIntoConstraints = YES, and an explicit content size, or else everything must have translatesAutoresizingMaskIntoConstraints = NO and the content size will be deduced implicitly based on the constraints of the subviews.

这是在<一个很好的解释href=\"http://developer.apple.com/library/ios/releasenotes/General/RN-iOSSDK-6_0/index.html\">http://developer.apple.com/library/ios/releasenotes/General/RN-iOSSDK-6_0/index.html

这篇关于UIScrollView中不使用自动布局约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆