Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

多次调用 viewDidLayoutSubviews #33

Closed
xoxhk opened this issue Nov 30, 2015 · 3 comments
Closed

多次调用 viewDidLayoutSubviews #33

xoxhk opened this issue Nov 30, 2015 · 3 comments

Comments

@xoxhk
Copy link

xoxhk commented Nov 30, 2015

为什么我在我的项目中使用这些代码,在每次切换菜单的时候都会调用viewDidLayoutSubviews,导致menu每次都从0重新滚动一遍。而你的demo却没有,我自己做个实验,新建一个空白 的项目只放一个uiscrollview 每次向这个scrollview添加view的时候都会调用 viewDidLayoutSubviews。
真心很奇怪

@wangmchn
Copy link
Owner

hi, @xoxhk
是否在视图内部使用了Autolayout呢?
最近刚修复了这个引起的bug。
可以使用下最新的,看下bug是否还存在?

@xoxhk
Copy link
Author

xoxhk commented Nov 30, 2015

嗯,非常谢谢你提供的代码,我的每个的controller是从storybord加载的,内部有用autolayout,
我看到你修复的代码了,现在可以了,如果你有空能解释一下为什么就好了,
一直对autolayout的处理过程,导致相关回调函数被调用的情况不实很清楚
CGFloat oldSuperviewHeight = _superviewHeight;
_superviewHeight = self.view.frame.size.height;
if (_hasInited && _superviewHeight == oldSuperviewHeight) return;

@wangmchn
Copy link
Owner

这段代码主要是判断了 如果 self.view 的高度不变,就禁止下面的代码执行。
(下面代码有对scrollView的contentOffset进行改变)
由于autolayout的存在,在scrollView滚动时会调用 -viewDidLayoutSubviews(具体系统是如何调用的还有待研究,如果知道还望告知),此时会引起重设contentOffset的情况,导致无法滚动或是滚动异常。

@xoxhk xoxhk closed this as completed Nov 30, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants