简体   繁体   English

iPhone中的Scrollview中的图像

[英]Image inside Scrollview in iPhone

I am new to iPhone, 我是iPhone新手,

I want to do scrolling in my image which is inside scrollView but i am unable to scroll my image, 我想在scrollView内的图像中进行滚动,但是我无法滚动图像,

Here is my code snippet, 这是我的代码段,

UIImage *image1 = [UIImage imageWithContentsOfFile:@"768bg_with_footer.gif"];
self.imageView = [[UIImageView alloc] initWithImage:image1];
[self.scrollView addSubview:self.imageView];
scrollView.contentSize = image1.size;
self.scrollView.contentOffset = CGPointZero;

I have taken ScrollView in my .xib file. 我在.xib文件中使用了ScrollView。

Any help will be appreciated. 任何帮助将不胜感激。

Try this code: 试试这个代码:

UIImage *image1 = [UIImage imageNamed:@"768bg_with_footer.gif"];
self.imageView = [[UIImageView alloc] initWithImage:image1];
[self.scrollView addSubview:self.imageView];
scrollView.contentSize = image1.size;
self.scrollView.contentOffset = CGPointZero;

We use initWithContentsOfFile when we know the path of the image.Using it with imageName will give a null image. 当我们知道图像的path时,我们使用initWithContentsOfFile ,将其与imageName一起使用将得到一个空图像。

尝试跟随

self.scrollView.contentSize = self.imageView.frame.size;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM