我在 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 contentOffset 更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
阻止 UITableView 自动滚动Stop a UITableView from automatically scrolling(阻止 UITableView 自动滚动)
iOS UIScrollView 延迟加载iOS UIScrollView Lazy Loading(iOS UIScrollView 延迟加载)
在 iOS 5 模拟器上运行时,使用 iOS 6.0 SDK 并为 iusing iOS 6.0 SDK and building for iOS 5 Target causes UIScrollView setMinimumZoomScale to fail when running on iOS 5 simulator(在 iOS 5 模拟器上运
以编程方式创建部分屏幕 UIPageViewControllerCreate partial-screen UIPageViewController programmatically(以编程方式创建部分屏幕 UIPageViewController)
如何使用或不使用 ScrollView 使 ImageView 可缩放?how to make an ImageView zoomable with or without ScrollView.?(如何使用或不使用 ScrollView 使 ImageView 可缩放?)
UIImageView 在 UIScrollView 中缩放和捏合UIImageView zoom and pinch in UIScrollView(UIImageView 在 UIScrollView 中缩放和捏合)