我有几个按钮,每个按钮加载一个不同的图像 UIScrollView,你可以放大这些图像。发生的情况是,在选择新图像后,前一个图像仍然存在于滚动视图中。在其中打开新图像之前如何清理滚动视图?
这是到目前为止的代码:
- (UIView *) viewForZoomingInScrollView: (UIScrollView *)scrollView{
return imgView;
}
-(IBAction)buttonClicked: (UIButton *)sender{
switch (sender.tag) {
case 1:{
UIImageView *myImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Gath.jpg"]];
self.imgView = myImageView;
[myImageView release];
scrollView.contentSize = CGSizeMake(imgView.frame.size.width, imgView.frame.size.height);
scrollView.maximumZoomScale = 4.0;
scrollView.minimumZoomScale = 1.0;
scrollView.clipsToBounds = YES;
scrollView.delegate = self;
[scrollView addSubview:imgView];
}
}
}