图片放大问题
来源:6-2 作业题
盛益华通
2018-06-25 16:18:39
如何实现点击大图按钮将这张图片进行放大缩小
麻烦老师详细解答或用代码解释一下 困扰好多天了
1回答
imoocLovers
2018-06-25
①点击按钮,通过判断你定义的bool变量是真还是假来进行放大和缩小,下面是放大和缩小的代码:
点击button时调用下面代码: static BOOL showLarge = YES; showLarge = !showLarge; if (showLarge) { [UIView animateWithDuration:1.5 animations:^{ self.imageView.frame = CGRectMake(0, (CGRectGetHeight([UIScreen mainScreen].bounds) - CGRectGetWidth([UIScreen mainScreen].bounds)) / 2, CGRectGetWidth([UIScreen mainScreen].bounds), CGRectGetWidth([UIScreen mainScreen].bounds)); }];//表示要进行放大 } else { [UIView animateWithDuration:1.5 animations:^{ self.imageView.frame = _originImageViewRect; }];//表示恢复到原来的尺寸,_originImageViewRect用来记录imageView刚开始的尺寸 }
②点击图片进行放大缩小,为图片添加手势。参考代码:
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didClickImageView)]; self.imageView.userInteractionEnabled = YES; [self.imageView addGestureRecognizer:tap];
在手势的响应方法里面完成图片的放大和缩小。
相似问题