UIScrollView contentSize 不起作用

2022-10-16移动开发问题
57

本文介绍了UIScrollView contentSize 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我在 nib 的 view 中放置了一个 UIScrollView,并将其链接到一个 IBOutlet 属性.

I put a UIScrollView in my nib's view, and linked it to a an IBOutlet property.

现在,当我在 viewDidLoad 方法中执行此操作时,它似乎对 contentSize 没有影响:

Now, when I do this in my viewDidLoad method, it seems to have no effect on the contentSize:

self.sv.backgroundColor = [UIColor yellowColor]; // this works
CGSize size =  CGSizeMake(1000.0, 1000.0); 
[self.sv setContentSize:size]; // this does not

它的行为就好像 contentSize 与框架相同.这是怎么回事?当我关闭自动布局时,这开始工作.为什么?

It behaves as if the contentSize was the same as the frame. What's going on? This started working when I turned off AutoLayout. Why?

推荐答案

我也遇到了同样的问题.UIScrollView 的自动布局搞砸了.

I had the same problem. Auto Layout for UIScrollView is messed up.

解决方法:将 UIScrollView 中的所有内容放入另一个 UIView,并将该 UIView 作为 UIScrollView 的唯一子项.然后你可以使用自动布局.

Work around: Put everything in the UIScrollView into another UIView, and put that UIView as the only child of the UIScrollView. Then you can use Auto Layout.

如果接近尾声的事情搞砸了(无论您的 UIScrollView 滚动哪个方向的尾端),请将最后的约束更改为尽可能低的优先级.

If things near the end is messed up (the end of whichever direction your UIScrollView scrolls), change the constraint at the end to have the lowest possible priority.

这篇关于UIScrollView contentSize 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End
UIScrollView

相关推荐

UIScrollView 和 Cocos2D
UIScrollView and Cocos2D(UIScrollView 和 Cocos2D)...
2024-08-12 移动开发问题
2

如何在没有 UIScrollView 的情况下放大和缩小 UIImageView?
How can i zoom in and out in a UIImageView without UIScrollView?(如何在没有 UIScrollView 的情况下放大和缩小 UIImageView?)...
2024-04-15 移动开发问题
9

iPhone SDK:UIScrollView 不滚动
iPhone SDK: UIScrollView does not scroll(iPhone SDK:UIScrollView 不滚动)...
2024-04-15 移动开发问题
11

UIScrollView 分页自动布局 &故事板
UIScrollView Paging Autolayout amp; Storyboard(UIScrollView 分页自动布局 amp;故事板)...
2023-09-12 移动开发问题
7

在 UIScrollView 的底部查看,带有 AutoLayout
View at the bottom in a UIScrollView, with AutoLayout(在 UIScrollView 的底部查看,带有 AutoLayout)...
2023-09-11 移动开发问题
1

dequeueReusableCell 打破了cliptobounds
dequeueReusableCell breaks cliptobounds(dequeueReusableCell 打破了cliptobounds)...
2023-09-09 移动开发问题
1