开发者

a problem to load imageView to scrollView

I am an new user of Objective-c. I have a problem to load imageview to scrollview.

I use interface builder to add a scrollview onto view. and then I try to add an imageview on the scrollview by code.

UIImage *image = [[[UIImage alloc]init]autorelease]; image = [UIIamge imageNamed:@"cover.jpg"];

imageView = [[[UIImageView alloc]init]autorelease]; imageVIew.frame = CGRectMake(50.0, 40.0, 200.0,200.0); imageView.image =开发者_JAVA百科 image;

[scorllView addSubview:imageView];

then I add another imageView onto the ScrollView with position at (50.0,1000.0) and length = 200, width = 200 (the screen of ipad is 786*1004) the photos can appear on the screen. The second photo is not complete, and I try to scroll the screen, however I can't scroll it.

Thanks.


first, you only need

UIImage * image = [UIImage imageNamed:@"cover.jpg"];
class methods(imageNamed: here) that creates the instance of it other than "alloc" would create a autoreleased object.

[UIImage imageNamed:@"cover.jpg"] is conceptually identical to
[[UIImage alloc] initWithFileContents:@"cover.jpg"] autorelease] // note, alloc once, release once.
(it may not be identical internally, imageNamed: caches the image initWithFileContents: might not)

In order to scroll the scrollView, there are many things you need to make sure.

One of it is to make sure your scrollView's contentSize is bigger than your scrollView's frame size.
try setting your scrollView.contentSize = CGSizeMake(someBigValue, someBigValue);

The content inside scrollView scrolls inside the scrollView. So your content should be bigger than scrollView's frame size to scroll.


you have to increase contentinset or UIScrollview to make it scrollable, You can increase bottom,

scorllView.contentInset = UIEdgeInsetsMake(0, 0, 680, 0);

or increase as you need

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜