我可以使用swift使用捏合手势进行捏缩放。但是在图像放大后,我无法查看哪个是不可见的。 (即)无法在屏幕周围移动图像。任何人都可以帮助我吗?
我的代码:
@IBAction func scaleImage(sender: UIPinchGestureRecognizer) {
sender.view!.transform = CGAffineTransformScale(sender.view!.transform, sender.scale, sender.scale)
sender.scale = 1
}
我需要在缩放后查看完整图像。
答案 0 :(得分:1)
添加ScrollView并在scrollView上添加图像
class ViewController:UIScrollViewDelegate{
@IBOutlet var imageView: UIImageView!
@IBOutlet var scroll: UIScrollView!
override func viewDidLoad() {
super.viewDidLoad()
scroll.maximumZoomScale=4;
scroll.minimumZoomScale=1.0;
scroll.bounces=true;
scroll.bouncesZoom=true;
scroll.contentSize=CGSizeMake(imageView.frame.size.width, imageView.frame.size.height);
scroll.showsHorizontalScrollIndicator=true;
scroll.showsVerticalScrollIndicator=true;
scroll.delegate=self;//assigning delegate
self.scroll.addSubview(imageView);
self.view.addSubview(scroll);
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func viewForZoomingInScrollView(_ scrollView: UIScrollView) -> UIView?
{
return self.imageView
}
}