当前位置: 动力学知识库 > 问答 > 编程问答 >

objective c - Issue with UIScrollView starting in different position iPhone vs iPad

问题描述:

My project is set up to be Universal. I have a view in which a ScrollView fills (and exceeds) the view size. It's larger vertically, so that the contents scroll up/down. When I run this on any iPhone simulator version (4.2...5.x, and retina) the ScrollView starts with the contents at the top - the way I want it to. However when I run it on the iPad simulator (any version) the contents start at the bottom - reverse of the iPhone.

I've read several threads and I've tried using scrollRectToVisible and scrollContentOffset but they both are quite annoying to see (animated or not). I've tried them in viewDidLoad or viewDidAppear or viewWillAppear and it always looks annoying as you can see the contents shift after the view appears.

The scrollwview and it's contents are added via the IB. For the iPhone, both are positioned correctly in the IB. For the iPad I change the size and content size of the scrollview in 'viewDidLoad' like so:

[helpScroll setContentSize:CGSizeMake(320, 1200)];

tmpFrame=helpScroll.frame;

tmpFrame.size.height=1004;

helpScroll.frame=tmpFrame;

Does anyone know why the iPad seems reversed from the iPhone and how to fix this?

网友答案:

I solved the issue. I had followed a tutorial which added items (ImageView, TextView, etc.) directly to the ScrollView and this caused problems when I resized the ScrollView. I found another tutorial which recommended using a View to hold the contents, then adding the View as a sub-view to the ScrollView. This works perfectly.

Here's the other tutorial: http://redartisan.com/2010/5/23/scrolling-with-uiscrollview

分享给朋友:
您可能感兴趣的文章:
随机阅读: