Make Difference between Double Tap and Single Tap in UIView


Hello guys, today I want to talk about Tap in iOS. Of course in swift because Objective-C now is less used for iOS Developer. If we see Instagram app, we can tap an image with double tap. After that an event has occured. If it's in Instagram we can have an event which is we like that photo with heart animation color changed.

If we single tap, it doesn't do nothing in photo but in video we can play the sound of the video. But if we double tap it, the sound would not interrupted by first tap. If we don't set something in iOS code, we can see interrupting happened.

Fortunately we can handle it easily in coding with swift. It just need one line of code to avoid interrupting single tap. But first make sure we have added two gesture recognizer. UITapGestureRecognizer is the class we need it to set. Don't worry I give you an example below.

I give you an example that I have an UIView called videoPlayerSuperview. The view is useful to show video player.  Because I have inserted AVPlayerLayer inside it. My first tap I used for playing video play and pause. And for double tap I used for liking the post like Instagram does. Make sure you initialize two UITapGestureRecognizer to handle first tap and double tap.



Yes, that's simple code to be used to avoid single tap when we want to double tap. Thanks for reading my post. I hope this little knowledge can help your apps become better. If you have any question, please feel free to ask in comment below. I hope this pandemic can pass quickly.

Popular posts from this blog

How to restart the app with flutter Android and iOS

How to have ConstraintLayout inside ScrollView and ScrollView inside ConstraintLayout Android

Missing system image Android Studio solution