Amit Hagin
Amit Hagin

Reputation: 3226

UIGestureRecognizer is delayed after UIView has changed its size

I have a view and a subview inside it. In the subview there are a few Gesture Recognizers that work. They are all added normally when the subview is created, for example:

let assetViewTapGesture = UITapGestureRecognizer(target: self, action: #selector(self.handleAssetViewTap(_:)))
    assetViewTapGesture.delegate = self
    assetView.addGestureRecognizer(assetViewTapGesture)

in the superview I have a UIPinchGestureRecognizer, that calls a function in the subview, which, in its turn changes sizes of frames in the subview:

    public func scale(newWidth:CGFloat){
    let factor:CGFloat = newWidth / self.internalAssetView.frame.width
    self.internalAssetView.frame = CGRect(x: self.internalAssetView.frame.origin.x, y: self.internalAssetView.frame.origin.y, width: newWidth, height: self.internalAssetView.frame.height)
    self.frame = CGRect(x: self.frame.origin.x, y: self.frame.origin.y, width: newWidth + additionParameter, height: self.frame.height)
}

When I pinch, everything behaves well, and the views change their sizes the way they should.

The problem: after the pinch ends, I tap in order to fire the TapGestureRecognizer inside the subview. It is being fired, but only after a few seconds. Actually - the more I pinch the views, the longer I wait, between tapping the screen and the actual firing of the recognizer. How come changing views's frames can affect the delay of a Gesture Recognizer's firing?

Upvotes: 0

Views: 355

Answers (1)

Shehryar Ahmad Rajput
Shehryar Ahmad Rajput

Reputation: 72

I do not know the reason for this however, I can offer a solution that might mitigate your issue.

There is no need to add an independent tap gesture, in-fact every single UIVIEW has a touches method. So you can delete the tap gesture and try typing this function

override func touchesBegan()

I've omitted the arguments, when you start typing touches... it will auto complete. Put the code you want to execute within it. Similarly there are touches started, touches ended methods also which you can use. Try the UIVIEW Touch methods. Hopefully they wont lag and your issue will be resolved.

Upvotes: 1

Related Questions