弹回 UIViewController 后 UIScrollView 的原点发生变化

UIScrollView#39;s origin changes after popping back to the UIViewController(弹回 UIViewController 后 UIScrollView 的原点发生变化)
本文介绍了弹回 UIViewController 后 UIScrollView 的原点发生变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我有一个 UIViewController 子类作为情节提要中的场景,其中包含一个包含各种子视图的 UIScrollView.其中一个子视图是一个 UIButton ,它进入另一个场景 UIViewController 子类.当我从视图返回时(将 UIViewController 从导航控制器堆栈中弹出),我发现滚动视图的原点发生了某种变化,尽管 contentsizecontentoffset 看起来是正确的.

I have a UIViewController subclass as a scene in the storyboard that contains a UIScrollView containing various subviews. One of the subviews is a UIButton which segues into another scene UIViewController subclass. When I come back from the view (pop the UIViewController off the navigation controller stack), I find that the scroll view's origin has somehow changed, although the contentsize and contentoffset seem correct.

另外有趣的是,该应用程序有一个标签栏,当我离开并返回该视图时,滚动视图被正确设置为偏移量为 (0, 0).

What's also interesting is that the app has a tab bar, and when I tab away and back to that view, the scroll view is set back correctly with offset at (0, 0).

这个过程基本上不涉及任何代码,因为它几乎都在情节提要中.由于我对使用情节提要相当陌生,因此我认为我做错了,尽管我不知道是什么.关于那可能是什么的任何想法?也许是规模问题或限制?

There is basically no code involved in this process, as it's pretty much all in the storyboard. As I am fairly new to using the storyboard, I figure I'm doing something wrong, although I don't know what. Any ideas as to what that may be? Perhaps sizing issues or constraints?

推荐答案

其实我把那行代码放在viewDidDisappear中,为了让view重新出现时记住偏移量,我加了这个前一行

Actually, I put that line of code in viewDidDisappear, and so that it remembers the offset when the view reappears, I added this line before it

 self.contentOffset = self.scrollView.contentOffset;

还有

 - (void)viewDidLayoutSubviews { 
       self.scrollView.contentOffset = self.contentOffset; 
 }

这篇关于弹回 UIViewController 后 UIScrollView 的原点发生变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

UIButtons at the bottom of UIScrollView not working(UIScrollView 底部的 UIButtons 不起作用)
scrollViewWillEndDragging:withVelocity:targetContentOffset: not working on the edges of a UISCrollView(scrollViewWillEndDragging:withVelocity:targetContentOffset: 不在 UISCrollView 的边缘工作)
ImageView Scaling when scrolling down(向下滚动时 ImageView 缩放)
Bounds automatically changes on UIScrollView with content insets(UIScrollView 上的边界自动更改,带有内容插图)
iOS5 UITapRecognizer for UIScrollView interfering with buttons. How to fix?(用于 UIScrollView 的 iOS5 UITapRecognizer 干扰按钮.怎么修?)
Handling scroll views with (custom, interactive) view controller presentation and dismissal(使用(自定义、交互式)视图控制器呈现和解除处理滚动视图)