UIScrollView的原点在弹出回到UIViewController后改变 [英] UIScrollView's origin changes after popping back to the UIViewController

查看:105
本文介绍了UIScrollView的原点在弹出回到UIViewController后改变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 UIViewController 子类作为一个场景的故事板,包含 UIScrollView 包含各种子视图。其中一个子视图是一个 UIButton ,它插入另一个场景 UIViewController 子类。当我从视图回来(弹出 UIViewController 关闭导航控制器堆栈),我发现滚动视图的原点有所改变,虽然 contentize contentoffset 似乎是正确的。

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 ,以便它记住视图重新出现时的偏移量,我在它之前添加了这一行

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; 
 }

这篇关于UIScrollView的原点在弹出回到UIViewController后改变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆