not able to add pan aswell as pinch gesture to the image view
Closed this issue · 2 comments
i am adding a pan as-well as pinch gesture to the imageview inside the item view same as you added tap gesture but it is zooming in wrong way.
and both gestures are not working simultaneously
fileprivate func addImageViews() {
for i in 0..<itemCount {
let itemView = createImageView(i)
// itemView.isUserInteractionEnabled = true
self.dataSource?.collageView(self, configure: itemView, at: i)
addTapGesture(to: itemView)
// addPanGesture(to: itemView)
addPinchGesture(to: itemView)
imageViews.append(itemView)
self.addSubview(itemView)
}
}
i am modifying here and methods are
fileprivate func addPanGesture(to item: CollageItemView){
let panGesture = UIPanGestureRecognizer(target: self, action: #selector(handlePan(_:)))
item.imageView.addGestureRecognizer(panGesture)
item.isUserInteractionEnabled = true
}
fileprivate func addPinchGesture(to item:CollageItemView){
let pinchGesture = UIPinchGestureRecognizer(target: self, action: #selector(handlePinch(_:)))
item.imageView.addGestureRecognizer(pinchGesture)
item.imageView.isUserInteractionEnabled = true
}
@objc fileprivate func handlePinch(_ sender:UIPinchGestureRecognizer){
// guard let item = itemView.collageItem else { return }
// self.delegate?.collageView!(self, pinchGesture: sender)
if let view = sender.view as? UIImageView {
view.transform = view.transform.scaledBy(x: sender.scale, y: sender.scale)
sender.scale = 1
}
}
@objc fileprivate func handleTap(_ sender: UITapGestureRecognizer) {
let itemView = sender.view as! CollageItemView
guard let item = itemView.collageItem else { return }
self.delegate?.collageView?(self, didSelect: itemView, at: item.indexForImageArray)
}
please do the helpfull Thanks :)
Hi,
I guess you should work with Simultaneously gesture as shown below:
func gestureRecognizer(UIGestureRecognizer, shouldRecognizeSimultaneouslyWithGestureRecognizer: UIGestureRecognizer) -> Bool {
return true
}