添加子视图或更改框架后

添加子视图或更改框架后

本文介绍了添加子视图或更改框架后 UIScrollView 不需要滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个充满子视图的 UIScrollView,在创建它和最初填充它时一切都很好.

I have a UIScrollView filled with subviews, all is well when creating it and initially filling it.

但是当我添加一个位于可见屏幕部分之外的新子视图时,或者当我只是调整也在可见屏幕部分之外的现有子视图的大小时,随后会出现一个 0.3 秒长的滚动动画(我可以从我的委托中看到它发生)似乎与新添加/调整大小的元素相匹配.

But when I add a new subview that is positionned outside of the visible screen portion, or when I just resize an existing subview that is also outside of the visible screen portion, there is a subsequent 0.3s-long scroll animation (I can see it happening from my delegate) that seems to match the newly added/resized element.

尝试:

  • pagingEnabled 始终为否.
  • 在子视图操作期间将 scrollEnabled 设置为 NO 没有帮助.
  • 在子视图操作后执行 setContentOffset:animated:NO 不会阻止动画.
  • 一个包含我所有子视图的巨大子视图无济于事.

我目前的解决方法是最初将框架设置为适合可见屏幕部分,或者在另一个超级视图中进行调整大小的工作,但感觉很脏,并且无法处理所有情况...

My current workaround is to initially set the frame to fit inside the visible screen portion, or doing resizing work inside another superview, but it feels dirty, and won't handle all situations...

有没有办法在以编程方式操作子视图时防止这种自动滚动动画?

Is there a way to prevent this automatic scrolling animation when programmatically manipulating subviews?

Xcode 4.3,iOS SDK 5.1.

Xcode 4.3, iOS SDK for 5.1.

推荐答案

我也发现了这个问题,找到了这个解决方案 http://www.iphonedevsdk.com/forum/iphone-sdk-development/94288-disabling-uiscrollview-autoscroll.html

I too discovered this problem and found this solution http://www.iphonedevsdk.com/forum/iphone-sdk-development/94288-disabling-uiscrollview-autoscroll.html

它涉及对 UIScrollView 进行子类化,并且在以下方法中不输入任何代码.

It involves subclassing the UIScrollView and entering no code in the following method.

- (void)scrollRectToVisible:(CGRect)rect animated:(BOOL)animated  {

}

就像那个人在链接上说的那样,我发现它有效,到目前为止没有问题.希望它对你有用.

Like the guy says on the link I've found it works and no problems so far. Hope it works for you.

这篇关于添加子视图或更改框架后 UIScrollView 不需要滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 08:42