>将滚动视图添加到根视图.
>将零空间固定到超视图的所有边缘.
>在上面的scrollvIEw中添加一个UIVIEw(contentVIEw).
>将零空格固定到scrollvIEw的所有边缘
>向contentVIEw添加一些小部件,并将contentVIEw的高度更改为2000.
=>这个contentVIEw在iOS 7中滚动,但我无法在iOS 8预览中使用相同的步骤.
即使它似乎在iOS 7中工作,我可能不会采取正确的方式吗?有什么建议?
解决方法 我很惊讶没有看到更多关于此的评论.滚动视图内部自动布局在iOS 8中大部分被破坏(截至撰写本文时为止).编辑这是在种子5中修复的,所以应该忽略这个注释!
该规则应该是(参见https://developer.apple.com/library/prerelease/ios/technotes/tn2154/_index.html),如果滚动视图(其子视图或子视图)的内容固定到滚动视图的所有四个边界,则它设置内容大小.
然而,在iOS 8中,这失败了 – 但是以一种奇怪的方式.只有当确定子视图的高度和宽度的约束都是绝对的而不是内在的时,它才会失败.
因此,例如,考虑该技术说明底部的代码,其中滚动视图和一个非常大的图像视图在代码中创建(这里是;我已经纠正了一个丢弃了at符号的小错误):
- (voID)vIEwDIDLoad { UIScrollVIEw *scrollVIEw; UIImageVIEw *imageVIEw; NSDictionary *vIEwsDictionary; // Create the scroll vIEw and the image vIEw. scrollVIEw = [[UIScrollVIEw alloc] init]; imageVIEw = [[UIImageVIEw alloc] init]; // Add an image to the image vIEw. [imageVIEw setimage:[UIImage imagenamed:@"MyReallyBigImage"]]; // Add the scroll vIEw to our vIEw. [self.vIEw addSubvIEw:scrollVIEw]; // Add the image vIEw to the scroll vIEw. [scrollVIEw addSubvIEw:imageVIEw]; // Set the translatesautoresizingMaskIntoConstraints to NO so that the vIEws // autoresizing mask is not translated into auto layout constraints. scrollVIEw.translatesautoresizingMaskIntoConstraints = NO; imageVIEw.translatesautoresizingMaskIntoConstraints = NO; // Set the constraints for the scroll vIEw and the image vIEw. vIEwsDictionary = NSDictionaryOfVariableBindings(scrollVIEw,imageVIEw); [self.vIEw addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[scrollVIEw]|" options:0 metrics: 0 vIEws:vIEwsDictionary]]; [self.vIEw addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[scrollVIEw]|" options:0 metrics: 0 vIEws:vIEwsDictionary]]; [scrollVIEw addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[imageVIEw]|" options:0 metrics: 0 vIEws:vIEwsDictionary]]; [scrollVIEw addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[imageVIEw]|" options:0 metrics: 0 vIEws:vIEwsDictionary]];}
该代码有效(假设您的图像非常大),因为图像视图的大小受内在约束的影响.但现在更改最后两行,如下所示:
[scrollVIEw addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[imageVIEw(1000)]|" options:0 metrics: 0 vIEws:vIEwsDictionary]]; [scrollVIEw addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[imageVIEw(1000)]|" options:0 metrics: 0 vIEws:vIEwsDictionary]];
现在你所拥有的是一个可在iOS 7上滚动但在iOS 8上不可滚动的滚动视图.进一步的调查显示这是因为内容大小保持在(0,0);它不尊重内容视图的绝对宽度和高度约束.
总结以上是内存溢出为你收集整理的UIScrollview自动布局似乎无法在iOS8 / Xcode 6预览中使用?全部内容,希望文章能够帮你解决UIScrollview自动布局似乎无法在iOS8 / Xcode 6预览中使用?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)