UIScrollView setContentSize 使用自动布局打破视图

2022-11-09移动开发问题
9

本文介绍了UIScrollView setContentSize 使用自动布局打破视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我在我的 iPhone 应用程序中使用自动布局并且有一个 UIScrollView.在我的应用程序运行时,我需要在几个点更改滚动视图的内容大小(因此在 viewWillAppear 中设置内容大小是没有用的,因为我在其他地方看到了这个建议).

I am using Auto Layout in my iPhone app and have a UIScrollView. I need to change the content size of my scroll view at several points while my apps running (so setting the content size in viewWillAppear is useless as I have seen this suggested in other places).

当我更改它时,我的子视图会跳来跳去,大概是因为它打破了自动布局约束.

When I change it, my subviews jump about, presumably because it breaks the auto layout constraints.

那么如何在启用自动布局的情况下更改滚动视图内容大小?

So how can I approach changing my scrollview content size with auto layout enabled?

谢谢.

推荐答案

我也遇到了同样的问题,我知道这不是最终的解决方案,但现在,而不是在 viewWillLayoutSubviews,通过将代码放在 viewDidLayoutSubviews 中,我可以在 viewController 完成默认业务后设置 contentSize :)

I was having this same issue, and I know this can't be the final solution, but for now, rather than calling this in viewWillLayoutSubviews, by putting the code inside viewDidLayoutSubviews it allowed me to set the contentSize AFTER the viewController did it's default business :)

希望对您有所帮助.

这篇关于UIScrollView setContentSize 使用自动布局打破视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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