推送另一个视图后 UIScrollView contentOffset 更改

UIScrollView contentOffset change after another view pushed(推送另一个视图后 UIScrollView contentOffset 更改)
本文介绍了推送另一个视图后 UIScrollView contentOffset 更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Interface Builder 中有一个 UIViewController,我在 UIView 中添加了一个 UIScrollView.它的 contentOffset 属性等于 0.0,但是当我将 UIScrollView 滚动到最底部并推送另一个视图时,contentOffset 会发生变化.

I have a UIViewController in Interface Builder, and I add a UIScrollView to the UIView. It has a contentOffset property equal to 0.0, but when I scroll the UIScrollView to the very bottom and push another view the contentOffset changes.

NSLog 给了我以下值:

//View just loaded
2013-09-09 16:19:27.455 my_app[24588:907] Scroll View content offset is 0.000000

//We came back from another view
2013-09-09 16:19:30.957 my_app[24588:907] Scroll View content offset is 108.000000

这种行为的原因是什么?我刚刚在 IB 中添加了一个 UIScrollView 并且在代码中什么也没做.

What's the reason of this behaviour? I've just added a UIScrollView in IB and did nothing in code at all.

scrollView的contentHeight大于self.view.height.scrollView 的 frame 保持不变.

The contentHeight of the scrollView is bigger than self.view.height. The frame of the scrollView stays the same.

推荐答案

查看我的回答类似的问题.

您需要在 viewWillAppear:viewWillDisappear: 中适当地设置滚动视图的 contentOffset.

You need to set the scrollview's contentOffset appropriately in viewWillAppear: and viewWillDisappear:.

另外,请参阅:

  • 这个答案问题UIScrollView 弹回 UIViewController 后原点发生变化.
  • 这个相关问题,UIScrollview 自动布局问题.

这篇关于推送另一个视图后 UIScrollView contentOffset 更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

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

相关文档推荐

Why local notification is not firing for UNCalendarNotificationTrigger(为什么没有为UNCalendarNotificationTrigger触发本地通知)
iOS VoiceOver functionality changes with Bundle Identifier(IOS画外音功能随捆绑包标识符而变化)
tabbar middle tab out of tabbar corner(选项卡栏中间的选项卡角外)
Pushing UIViewController above UITabBar(将UIView控制器推送到UITabBar上方)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Get an event when UIBarButtonItem menu is displayed(显示UIBarButtonItem菜单时获取事件)