如何从模态转换返回后重置我的UIScrollView的位置? [英] How to reset my UIScrollView's position after returning from a modal transition?
问题描述
我有一个包含许多按钮的长视图的简单视图,整个内容位于 UIScrollView
中。 滚动条
效果很好,我可以滚动
到底部,然后点击按钮
。每个按钮
触发一个模态 seque到
另一个视图
。然后,用户交互解除了新的视图
,导致原始 UIScrollView的视图
再次加载。
I have a simple view containing a long view with many buttons, with the whole thing being in a UIScrollView
. The scroller
works well, and I can scroll
to the bottom and click a button
. Every button
triggers a modal seque to
another view
. That new view
is then dismissed by user interaction, causing the original UIScrollView's view
to load again.
这就是问题:如果我点击 UIScrollView
顶部的按钮,我输入模态 segue
,关闭新的视图
,并返回 UIScrollView的视图
,没有任何问题。但是,如果我点击 UIScrollView
底部的其中一个按钮,当我返回 seque
时,然后过渡回来,我的滚动都搞砸了。我只能在我的卷轴
下面看到区域,并且不能滚动
备份到了顶部!
Here's the problem: If I click on a button toward the top of the UIScrollView
, I enter the modal segue
, dismiss the new view
, and return to the UIScrollView's view
without a problem. But, if I click on one of the buttons toward the bottom of the UIScrollView
, when I return seque
out and then transition back, my scrolling is all messed up. I can only see the area beneath my scroller
, and can't scroll
back up to the top anymore!
我很确定必须有一些方法来重置 UIScrollView的
开始和结束指向 ViewWillAppear
,但我无法理解。感谢任何帮助!
I'm pretty sure there must be some way to reset the UIScrollView's
starting and ending points upon ViewWillAppear
, but I can't figure it out. Any help is appreciated!
另外,仅供参考,我只是通过界面构建器添加了 UIScrollView
,但还没有在任何地方实现或合成它。
Also, FYI, I simply added the UIScrollView
through interface builder, and haven't implemented or synthesized it anywhere yet.
推荐答案
试试这段代码:
- (void)viewWillAppear:(BOOL)animated
{
[yourscrollview setContentOffset:CGPointZero animated:YES];
}
这篇关于如何从模态转换返回后重置我的UIScrollView的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!