如何使用或不使用 ScrollView 使 ImageView 可缩放?
问题描述
我的 IB
中有一个 UImageView
,并在该 UImageView
上添加了一个地图图像.我想让该图像可以缩放.
I have an UImageView
in my IB
and added a map image on that UImageView
. I want to make that image pinch zoomable.
这是我的代码:
但这无济于事,我可以看到 UIScrollView
来了,但我的图像没有任何反应.
提前致谢.
but this doesn't help, I can see a UIScrollView
Coming but nothing happen to my image.
Thanks in advance.
推荐答案
在你的 ViewController.h
文件中添加 UIScrollViewDelegate
Add UIScrollViewDelegate
in your ViewController.h
file
然后将以下代码添加到您的 ViewController.m
文件中
then add following code to your ViewController.m
file
如果您使用此代码,则无需添加 UIPinchGestureRecognizer
No need to add UIPinchGestureRecognizer
if your using this code
修改viewDidLoad
如下
在此处指定要放大的imageView
Specify the imageView to zoom here
要避免 UIScrollView 在 zoomimg 上的奇怪行为,请使用此方法
To avoid the strange behaviour of UIScrollView on zoomimg use this method
然后在viewDidAppear上调用上面的方法
Then call the above method on viewDidAppear
看看这个 链接.我从那个链接学到了这项技术.
have a look at this link if you need more clarification. I learned this technique from that link.
这篇关于如何使用或不使用 ScrollView 使 ImageView 可缩放?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!