Sir*_*III 76 constraints objective-c uiscrollview autolayout
我有一个滚动视图和背后的图像视图,我用笔尖填充它.我正在使用autolayout.我有一个底层空间可以看到超级视图,还有一个顶层空间可以在两个视图上进行超视图.图像视图完全符合我的要求.对于iphone 5来说,它就是我想要它的地方.而对于其他iphone,它保持在屏幕底部之上,因此它可以正确调整大小.滚动视图在iphone 5上看起来是正确的,但在其他手机上它没有调整大小,所以它向下滚动到应用程序的视图下方.我在日志中收到这些消息:
 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];
从我所看到的,这只是从视图中取消所有约束.而这不是我想要的.
mat*_*att 175
UIScrollView和自动布局之间的关系不同于自动布局的其他方面.基本上,如果允许简单的自动布局操作,则不会滚动任何内容.例如,如果滚动视图的子视图以正常方式通过约束从滚动视图顶部的10个点固定,那么它将被绝对固定在那里; 无论滚动视图如何滚动,它都不会移动.
要解决此问题,使用autolayout的UIScrollView以全新的方式运行.因此,当您说"我正在使用自动布局"时,您必须准备好与以前完全不同的操作方式.您必须使用单个滚动视图子视图translatesAutoresizingMaskIntoConstraints = YES和显式内容大小,否则所有内容必须具有,translatesAutoresizingMaskIntoConstraints = NO并且将根据子视图的约束隐式推断内容大小.
这在https://developer.apple.com/library/content/releasenotes/General/RN-iOSSDK-6_0/index.html中有很好的解释.
pha*_*ann 161
使用自动布局时非常重要:您必须将最后一个子视图的右侧和/或底部固定在滚动视图的右侧和/或底部.这是滚动视图知道内容大小的方式.例如:
[scrollView addConstraint:[NSLayoutConstraint constraintWithItem:lastSubView
                                                 attribute:NSLayoutAttributeRight
                                                 relatedBy:NSLayoutRelationEqual
                                                    toItem:scrollView
                                                 attribute:NSLayoutAttributeRight
                                                multiplier:1.0
                                                  constant:0]];
我要感谢这个网站提供完美的例子.
因为这个原因,我失去了几个小时,我希望能让别人感到痛苦.
| 归档时间: | 
 | 
| 查看次数: | 83156 次 | 
| 最近记录: |