Ios 在uiscrollview中向uiimageview添加手势(平移、双击、捏)
目前,我正在尝试创建某种类型的imageviewer,您可以在其中单击一个图像,然后以全尺寸显示。现在我想给它添加手势来缩放。我想了解并了解如何添加收缩手势来放大和缩小图像,能够在图像周围平移并使用双击手势快速放大。我没有找到太多好的教程 我知道你要放大视图,而不是图像。这就是为什么要使用包含ImageView的ScrollView。现在,启用缩放、收缩和移动图像缺少什么 提前感谢您提供的任何有用的帖子 下面是此功能的“我的”当前代码库。需要补充什么Ios 在uiscrollview中向uiimageview添加手势(平移、双击、捏),ios,uiscrollview,uiimageview,zooming,uigesturerecognizer,Ios,Uiscrollview,Uiimageview,Zooming,Uigesturerecognizer,目前,我正在尝试创建某种类型的imageviewer,您可以在其中单击一个图像,然后以全尺寸显示。现在我想给它添加手势来缩放。我想了解并了解如何添加收缩手势来放大和缩小图像,能够在图像周围平移并使用双击手势快速放大。我没有找到太多好的教程 我知道你要放大视图,而不是图像。这就是为什么要使用包含ImageView的ScrollView。现在,启用缩放、收缩和移动图像缺少什么 提前感谢您提供的任何有用的帖子 下面是此功能的“我的”当前代码库。需要补充什么 class DetailViewContro
class DetailViewController: UIViewController, UIScrollViewDelegate {
var scrollView: UIScrollView!
var imageView: UIImageView!
override func viewDidLoad()
{
super.viewDidLoad()
self.navigationController?.isNavigationBarHidden = false
scrollView=UIScrollView()
scrollView.frame = CGRect(x: 0, y: 0, width: self.view.frame.width, height: (self.view.frame.height - (self.navigationController?.navigationBar.frame.size.height)! + 44))
scrollView.minimumZoomScale=1
scrollView.maximumZoomScale=3
scrollView.bounces=false
scrollView.delegate=self
self.view.addSubview(scrollView)
imageView=UIImageView()
imageView.image = UIImage(named: "inlinelogo.jpg")
imageView.frame = CGRect(x: 0, y: 0, width: scrollView.frame.width, height: scrollView.frame.height - (44 + UIApplication.shared.statusBarFrame.size.height))
imageView.backgroundColor = .black
imageView.contentMode = .scaleAspectFit
scrollView.addSubview(imageView)
}
func viewForZoomingInScrollView(scrollView: UIScrollView) -> UIView?
{
return imageView
}
}
您错过了
UIImageView
add的userInteractionEnabled
属性
imageView.isuserInteractionEnabled = true
您错过了
UIImageView
add的userInteractionEnabled
属性
imageView.isuserInteractionEnabled = true
启用imageView userInteractionEnabled属性启用imageView userInteractionEnabled属性