ScrollView content size does not work

I setup up a ScrollView as root view for one of my view controllers. When I dragged the scroll view from the Interface builder, the scroll came up with an initial size of 220×120.

In that view controller viewDidLoad method, I have this code.

UIImage *iphone = [UIImage imageNamed:@"iphone4s.jpg"];
imageview = [[UIImageView alloc] initWithImage:iphone];
[self.view addSubview:imageview];

[(UIScrollView*)self.view setContentSize:[iphone size]];

the iphone
image size is 600×800.

But the scroll view still is in size 220×120 when the view loads up on the screen. Should I do anything else to stretch the scrollView. Please help.

The property contentSize
is not the same as the size of the UIScrollView. Normally you’ll have a bigger content size in order to be able to scroll:

|x------------+     |
||            |     |
||            |     |
|+------------+     |
|                   |
|                   |

The inner rect in this sketch is the scroll view size (your 220×120), what you see in the screen, while the outer rect is the actual size of the object (600×800 in your case). Manipulating contentOffset
point (the x in the figure) you can change which portion of the object is visible.

If you don’t need the image to be scrollable, you don’t need a UIScrollView at all. Try with the UIImageView, change its frame
and check the different values of its contentMode

Also, don’t forget that views can auto adjust its size.

Hello, buddy!责编内容来自:Hello, buddy! (源链) | 更多关于

本站遵循[CC BY-NC-SA 4.0]。如您有版权、意见投诉等问题,请通过eMail联系我们处理。
酷辣虫 » 移动开发 » ScrollView content size does not work

喜欢 (0)or分享给?

专业 x 专注 x 聚合 x 分享 CC BY-NC-SA 4.0

使用声明 | 英豪名录