放大 UIScrollView 不起作用
有人可以帮我用 UIScrollView 进行缩放吗?
我正在尝试添加从 URL 检索到的三个图像并使用 UIScrollView 显示它。我可以做显示部分,但缩放不起作用。我希望有人能给我一些灯光。
我的 .h 文件
@interface TestScrollViewViewController : UIViewController <UIScrollViewDelegate>{
IBOutlet UIScrollView *scrollView;
UIImageView *subview;
}
@property (nonatomic, retain) UIScrollView *scrollView;
@property (nonatomic, retain) UIImageView *subview;
@end
.m 文件
- (void)viewDidLoad {
[super viewDidLoad];
UIImage *page1 = [[UIImage alloc] initWithData:[[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://abc.com/001.jpg"]]];
UIImage *page2 = [[UIImage alloc] initWithData:[[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://abc.com/002.jpg"]]];
UIImage *page3 = [[UIImage alloc] initWithData:[[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://abc.com/003.jpg"]]];
NSArray *images = [NSArray arrayWithObjects: page1, page2, page3, nil];
for (int i = 0; i < images.count; i++) {
CGRect frame;
frame.origin.x = self.scrollView.frame.size.width * i;
frame.origin.y = 0;
frame.size = self.scrollView.frame.size;
subview = [[UIImageView alloc] initWithFrame:frame];
subview.image = [images objectAtIndex:i];
self.scrollView.minimumZoomScale=0.5;
self.scrollView.maximumZoomScale=6.0;
self.scrollView.delegate=self;
[self.scrollView addSubview:subview];
[subview release];
}
self.scrollView.contentSize = CGSizeMake(self.scrollView.frame.size.width * images.count, self.scrollView.frame.size.height);
}
,这是 viewForZoomingInScrollView 方法
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
return self.scrollView;
}
真的希望有人能提供帮助。谢谢。
劳伦斯
can someone help me on doing zooming with the UIScrollView?
I am trying to add the three images retrieved from an URL and display it using a UIScrollView. I can do the display part but the zooming is not working. I hope someone can show me some lights.
My .h file
@interface TestScrollViewViewController : UIViewController <UIScrollViewDelegate>{
IBOutlet UIScrollView *scrollView;
UIImageView *subview;
}
@property (nonatomic, retain) UIScrollView *scrollView;
@property (nonatomic, retain) UIImageView *subview;
@end
the .m file
- (void)viewDidLoad {
[super viewDidLoad];
UIImage *page1 = [[UIImage alloc] initWithData:[[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://abc.com/001.jpg"]]];
UIImage *page2 = [[UIImage alloc] initWithData:[[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://abc.com/002.jpg"]]];
UIImage *page3 = [[UIImage alloc] initWithData:[[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://abc.com/003.jpg"]]];
NSArray *images = [NSArray arrayWithObjects: page1, page2, page3, nil];
for (int i = 0; i < images.count; i++) {
CGRect frame;
frame.origin.x = self.scrollView.frame.size.width * i;
frame.origin.y = 0;
frame.size = self.scrollView.frame.size;
subview = [[UIImageView alloc] initWithFrame:frame];
subview.image = [images objectAtIndex:i];
self.scrollView.minimumZoomScale=0.5;
self.scrollView.maximumZoomScale=6.0;
self.scrollView.delegate=self;
[self.scrollView addSubview:subview];
[subview release];
}
self.scrollView.contentSize = CGSizeMake(self.scrollView.frame.size.width * images.count, self.scrollView.frame.size.height);
}
and this is the viewForZoomingInScrollView method
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
return self.scrollView;
}
Really hope someones can help. Thanks.
Lawrence
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
替换
为
Replace
With
这就是问题所在。您不能在此处返回滚动视图本身,您必须返回要缩放的子视图。
That's what's wrong. You can't return the scroll view itself here, you must return it's subview that you want to zoom.