有人能幫助我縮放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;
}
真希望某人能有所幫助。謝謝。
勞倫斯
如果問題仍然存在請參考此問題http://stackoverflow.com/questions/6566996/with-uiscrollview-zoom-images-in-layout-frame/6567199#6567199 – rptwsthi