我想使用集合视图显示一些图像。我在滚动视图中使用单元格和图像视图中的scrollview。图像放大和缩小。当单元格被重用时,新的单元格滚动视图和图像视图大小与旧的缩放相同。 想要当单元格重用滚动视图大小默认时。 如何解决这个问题。
答案 0 :(得分:0)
@hello你必须在Imageview&中设置手势使用以下方法, 你可以轻松设置放大&使用手势缩小
在ViewDID中..
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
scrollViewMain.maximumZoomScale = 5.0;
scrollViewMain.minimumZoomScale = 1.0;
scrollViewMain.clipsToBounds = NO;
scrollViewMain.delegate = self;
UITapGestureRecognizer *tapTwice = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapTwice:)];
// set number of taps required
tapTwice.numberOfTapsRequired = 2;
// now add the gesture recogniser to a view
// this will be the view that recognises the gesture
[scrollViewMain addGestureRecognizer:tapTwice];
}
//------For Zoom IN ScrollView-------------------------------------------------------
-(UIView *)viewForZoomingInScrollView:(UIScrollView *)inScroll {
//self.iPickedPicture.center = ivPicture.center;
return _imgView;
}
- (void)tapOnce:(UIGestureRecognizer *)gesture
{
//on a single tap, call zoomToRect in UIScrollView
if ([scrollViewMain zoomScale] > 1.0)
{
float newScale = 1.0;
CGRect zoomRect = [self zoomToCenter:newScale withCenter:[gesture locationInView:scrollViewMain]];
[scrollViewMain zoomToRect:zoomRect animated:YES];
}
else
{
float newScale = 3.5;
CGRect zoomRect = [self zoomToCenter:newScale withCenter:[gesture locationInView:scrollViewMain]];
[scrollViewMain zoomToRect:zoomRect animated:YES];
}
}
- (void)tapTwice:(UIGestureRecognizer *)gesture
{
//on a double tap, call zoomToRect in UIScrollView
if ([scrollViewMain zoomScale] == 1.0) {
float newScale = [scrollViewMain zoomScale] * 3.5;
CGRect zoomRect = [self zoomToCenter:newScale withCenter:[gesture locationInView:scrollViewMain]];
[scrollViewMain zoomToRect:zoomRect animated:YES];
}else
{
float newScale = 1.0;
CGRect zoomRect = [self zoomToCenter:newScale withCenter:[gesture locationInView:scrollViewMain]];
[scrollViewMain zoomToRect:zoomRect animated:YES];
}
}
- (CGRect)zoomToCenter:(float)scale withCenter:(CGPoint)center {
CGRect zoomRect;
zoomRect.size.height = scrollViewMain.frame.size.height / scale;
zoomRect.size.width = scrollViewMain.frame.size.width / scale;
zoomRect.origin.x = center.x - (zoomRect.size.width / 2.0);
zoomRect.origin.y = center.y - (zoomRect.size.height / 2.0);
return zoomRect;
}