How to Add Multiple Gesture Recognizers to UI View?

In iOS app development, gestures play a very influential role in creating an engaging user interface. It basically contains taps, pinches, pans, or rotations for user input in navigation. Gesture functionality allows users to move, click or tap on their preferred area of the iOS mobile app screen.

 

Many iOS developers often face difficulty in adding multiple gesture recognizers to UIView. Gesture recognizers are a powerful and effective tool for adding user gesture functionality into the iOS app like tap, pinch, swipe, slide, and rotate. 

 

It enables users to execute actions such as triggering animations or view changes on the app screen. Hence, it is important to accurately add multiple gesture recognizers to UIView to engage users. Since we are an expert iOS app development company, we know how to add multiple gesture recognizers to UIView effectively. In this blog, we will tell you how to do it. 

So let’s get started

Overview of UIGesture Recognizer in iOS Development

Before you start implementing multiple gesture recognizers to UIView, you should know why [UIGestureRecognizer] is a useful tool and how to utilize it. 

 

Prior to this functionality, it was really difficult to add multiple gesture recognizer features in iOS app development. For instance, if there is a need for detecting a swipe, then iOS app developers have had to register for notifications such as [touchesBegan], [touchesMoved], and [touchesEnded] for each touch in [UIView]

 

This technique creates subtle bugs and inconsistency across iOS applications. It happens because iOS developers have had to write a little different code to recognize those touches. And therefore, adding multiple gestures takes a lot of work which increases time in the iOS development

 

Then Apple brought changes in Xcode to support iOS developers in adding feature features to iOS apps. With the current update, developers can easily create feature recognizer functionality in iOS mobile applications that detect common gestures. For example rotations, swipes, pans,  taps, long presses, and pinches. 

 

This updated feature helps developers in writing less code but also enables the app to work efficiently.  Hence, adding multiple gesture recognizer features to UIView in iOS app development is quite easier than before. 

 

Now, let’s start how to add multiple gesture recognizers to UIView in iOS apps. 

 

There are Seven Types of Gestures That Support iOS

  1. Tap Gesture Recognizer: Performing an action for tapping the UIObject.
  2. Pinch Gesture Recognizer: Used when need the zoom in and zoom out feature
  3. Rotation Gesture Recognizer: To perform the rotation on UIObject
  4. Swipe Gesture Recognizer: Four kinds of swipe gestures i.e. Top, left. Bottom, right
  5. Pan Gesture Recognizer: Help when we need to drag the UIObject anywhere on UIWindow
  6. Screen Edge Pan Gesture Recognizer: Special gesture used for 3-D touch
  7. Long Press: Generally used in the scenario when pressing the UIObject will pop up certain options

Here is a simple declaration of the UIViewController with a single UIImageView in it

class GesturePlayingController: UIViewController {

    let myImageView: UIImageView = {

        $0.contentMode = .scaleAspectFill

        $0.image = UIImage(named: "testImage")

        $0.isUserInteractionEnabled = true
 
       return $0

    }(UIImageView())      

    override func viewDidLoad() {

        super.viewDidLoad()
    }

 

We have declared the simple UIImageView with lazy initialization with its user interaction property enabled so that we can add multiple gestures to it.

Since no rocket science has been used so far, now we can add the gesture recognizer one by one to imageView. 

func addGesture() {

        let pan = UIPanGestureRecognizer(target: self, action: #selector(panImage))

        let rotate = UIRotationGestureRecognizer(target: self, action: #selector(handleRotation))        

        let pinch = UIPinchGestureRecognizer(target: self, action: #selector(pinchImage))

        myImageView.addGestureRecognizer(pinch)

        myImageView.addGestureRecognizer(pan)

        myImageView.addGestureRecognizer(rotate)

    }

@objc func panImage(_ recognizer: UIPanGestureRecognizer) {    

}
 
@objc func pinchImage(_ recognizer: UIPinchGestureRecognizer) { 

}

@objc func handleRotation(recognizer:UIRotationGestureRecognizer){

}

While adding the gesture recognizer to UIImageView, we need to give the selector that generally functions when the particular types of gestures are being performed.

Let us start with a simple PAN Gesture Recognizer

For moving the imageView in UIView, we need to set the translation from its initial position.

For example 

  @objc func panImage(_ recognizer: UIPanGestureRecognizer) {

        let translation = recognizer.translation(in: view)

        guard let view = recognizer.view else { return }

        view.center = CGPoint(x: view.center.x + translation.x, y: view.center.y + translation.y)

        recognizer.setTranslation(CGPoint.zero, in: view)
    }

 

After setting the translation, reset the translation to zero so that the next time when you perform the PAN on the imageView, it should start with zero.

Similarly, we can perform the PINCH and ROTATION Gesture on imageView.

@objc func pinchImage(_ recognizer: UIPinchGestureRecognizer) {

        guard let view = recognizer.view else{return}

        view.transform = view.transform.scaledBy(x: recognizer.scale, y: recognizer.scale)

        recognizer.scale = 1.0

    }

    @objc func handleRotation(recognizer:UIRotationGestureRecognizer){

        guard let view = recognizer.view else {return}

        view.transform = view.transform.rotated(by: recognizer.rotation)

        if recognizer.rotation == 0 { return }

        radian = recognizer.rotation

        recognizer.rotation = 0

    }

Conclusion

Adding multiple gesture recognizers to UIView in iOS app development is now easier and smoother than before. Developers now have to follow simple steps and write less code to implement the features. However, with growing innovations in UI development, users now expect more attractive and seamless features in UI. 

 

Therefore, to ensure you build an iOS app with intuitive UI features, you should try to create the app with an expert. And MobileCoderz is the top iOS app development company that has the industry’s most qualified and experienced iOS developers who can build really innovative and engaging UI features for your iOS mobile app.

Related Article

  • How-Much-Does-it-Cost-to-Build-an-MVP-App-in-2024
    How Much Does it Cost to Build an MVP App in 2024?
  • how-does-e-commerce-app-development-help-retailers-with-their-problems-in-the-retail-industry
    How Does E-Commerce App Development Help Retailers With Their Problems in the Retail Industry?
  • How-AI-is-Changing-the-Landscape-of-the-Online-Food-Delivery-Industry
    How AI is Changing the Landscape of the Online Food Delivery Industry?
peri hokiperihokiduta76duta 76ABC1131 - MPO SLOTABC1131 Bandar Slot Togelmix parlay agen slot qrisMPOGALAXYslot thailandabout usAWSBETmenganalisa pola dan rtp live untuk menjaga kemenangan mahjong sicbo gates olympus dengan teknik canggih duta76strategi canggih pola dan teknik untuk meraih menang mahjong ways 2 baccarat starlight princess analisa rtp live duta76teknik rahasia pola dan analisa strategi mahjong wins 3 blackjack sweet bonanza untuk mengoptimalkan rtp live duta76mengenal pola dan taktik mahjong ways 2 roulette wild west gold dengan analisa rtp live peluang jitu perihokioptimalkan peluang strategi teknik pola untuk menang mahjong wins 3 blackjack sabung ayam sv388 rtp live perihokimengungkap teknik rahasia mahjong sicbo gates olympus pola analisa rtp dan peluang menang di perihokimenganalisa rtp live pola strategi dan teknik kemenangan mahjong ways 2 baccarat starlight princess perihokimengenal strategi pola unik dan teknik mahjong wins 3 blackjack sweet bonanza peluang rtp live perihokirahasia strategi dan analisa pola mahjong ways 2 roulette wild bounty showdown untuk meraih kemenangan duta76pola peluang teknik analisa strategi mahjong wins 3 blackjack sabung ayam sv388 peluang rtp live jitu duta76aws atur sesi ritme wins3aws desain antarmuka ways2 polaaws mitos malam stabilitas ways2aws pemetaan interaksi simbol ways2aws pengalaman ritme mahjong waysaws peran scatter hitam wins3aws psikologis momen wins3aws strategi fase tenang waysaws transformasi pecah selayar wins3aws volatilitas tinggi wins3 rtpaws adaptasi mahjong pgsoftaws algoritma pragmatic rtpaws analisis intensitas mahjongaws analisis tumble olympusaws evaluasi berulang mahjongaws perhitungan matematis olympus scatteraws perubahan simbol mahjongaws probabilitas lucky neko kucingaws siklus scatter wins3 statistikaws stabilitas mahjong risikostrategi dan taktik unik untuk bisa menang mahjong sicbo gates olympus analisa pola rtp live duta76rahasia analisa teknik serta taktik pola mahjong ways 2 baccarat sweet bonanza maksimalkan rtp live duta76pola paling unik strategi dan taktik kemenangan mahjong wins 3 blackjack starlight princess dengan peluang rtp live duta76taktik jitu pola teknik mahjong ways 2 roulette wild bounty showdown maksimalkan peluang kemenangan rtp live perihokicara menyusun strategi rtp pola teknik dan analisa mahjong wins 3 blackjack sabung ayam sv388 untuk menang perihokiskema putaran aman mahjong wins 2 manajemen dana konsistenkajian struktural mahjong wins 3 konfigurasi mekanik februarisignifikansi simbol kunci fase awal sesi potensi hasilrespon adaptif fluktuasi energi grid mahjong ways durasi bermainpentingnya kontrol diri pergerakan fluktuatif mahjong wayskonvergensi multiplier volatilitas mahjong ways fase kritispanduan menjadi penguasa mahjong ways 2 pemahaman algoritmaimplementasi pola terarah kenyamanan keuntungan strategi digitaltips trik konsistensi mahjong ways analisis data transisi gridstrategi penguasaan pola simbol scatter wild mahjong wins 2konsep mekanisme mahjong ways stabilitas tempo ketahanan saldolangkah cerdas optimasi putaran mahjong ways nilai balikanstrategi menyusun kombinasi simbol mahjong pola acakcara terbaru akumulasi hasil besar mahjong ways strategi viralstabilitas pola mahjong ways transisi grid terjagapanduan eksklusif menerobos mekanisme mahjong wild deluxe gates of olympus sicbo teknik kalkulasi pembacaan rtp live duta76duta76 mengurai logika simbol mahjong ways 2 pgsoft pola kartu baccarat dan starlight princess melalui teknik observasi berbasis rtp livemembongkar celah peluang jitu mahjong wins 3 pragmatic blackjack sweet bonanza melalui teknik observasi strategi penempatan adaptif duta76mengurai mekanisme simbol mahjong ways 2 pgsoft putaran roulette scatter wild west gold melalui taktik kalkulasi entropi berbasis peluang terukur duta76teknik membaca peluang mahjong wins 3 pragmatic sabung ayam sv388 blackjack lewat analisa ritme siklus strategi kalkulasi presisi adaptif duta76membongkar logika simbol mahjong wild deluxe pola dadu sicbo cascade gates of olympus strategi observasi frekuensi berbasis data perihokianalisa perihoki volatilitas mahjong ways 2 pgsoft baccarat starlight princess taktik pola rtp live dan teknik prediksi peluang lintas permainanpemetaan anomali rtp live sweet bonanza blackjack mahjong wins 3 pragmatic strategi pembacaan pola silang taktik manajemen berbasis frekuensi perihokidekonstruksi siklus bonus wild bounty hunter putaran roulette frekuensi mahjong ways 2 pgsoft melalui taktik analitis eksklusif berbasis rtp live terukur perihokitaktik mendeteksi ritme sabung ayam sv388 mahjong wins 3 pragmatic blackjack pendekatan kalkulasi pola presisi terjamin perihokiteknik pembacaan pola multiplier cascade distribusi tile dalam gates of olympus mahjong wild deluxe sicbo dengan kalkulasi terukur perihokipanduan holistik menembus mekanisme distribusi kartu baccarat simbol mahjong ways 2 pgsoft multiplier starlight princess melalui taktik analisa rtp live perihokimenavigasi pola cluster sweet bonanza siklus kartu blackjack tile mahjong wins 3 pragmatic analisa momentum rtp live adaptif taktik lintas perihokitaktik mendeteksi ritme kemenangan wild west gold mahjong ways 2 pgsoft roulette pendekatan probabilitas kalkulasi momentum presisi eksklusif duta76mengurai mekanisme distribusi simbol mahjong wins 3 pragmatic kartu blackjack sabung ayam sv388 melalui taktik kalkulasi berbasis peluang terukur duta76aws grid rtp mahjongaws logika matematika mahjongaws logika strategi mahjongaws pengelolaan modal mahjongaws perubahan alur mahjongaws sinkronisasi simbol mahjongaws strategi rahasia mahjongaws tempo respon mahjongaws variasi pola mahjongaws wild momentum mahjongaws adaptasi transisi mahjongaws analisis keputusan mahjongaws analisis retrigger mahjongaws deteksi suasana mahjongaws pembaruan sistem mahjongaws perubahan tempo mahjongaws target awal mahjongaws tips statistik mahjongaws transisi fase mahjongaws wild emas mahjonge4 formula stabil dengan evaluasi rtp berkalae4 manajemen saldo profesional dalam mahjong wins 3e4 mental tangguh ala atlet olimpiade untuk scatter hitam mahjong wins 2e4 metode main disiplin dengan rtp stabil paling dicarie4 mindset juara dan pola main konsisten mahjong wins 2e4 optimasi hasil dengan strategi data drivene4 pendekatan modern mahjong wins berbasis statistike4 pendekatan terstruktur mengikuti irama sistemdekonstruksi mekanik scatter hitam mahjong ways akumulasi tinggimanajemen finansial terpadu dinamika putaran mahjong winsevolusi algoritma mahjong ways 2 arena ketangkasan digital 2026analisis sinkronisasi energi multiplier starlight princess fase akumulasirekonstruksi mekanik multiplier sugar rush 1000 konsistensi hasilintegrasi narasi budaya multiplier gates of gatot kaca strategi digitalmetodologi pemetaan roda keempat aztec gems peluang transisidekonstruksi mekanik tumble multiplier sweet bonanza akumulasi terstrukturanalisis volatilitas sticky wild wild west gold stabilitas sesiharmonisasi ekspansi simbol koi gate ketahanan saldo ritme bermainefektivitas multiplier berjenjang lucky neko pertumbuhan hasilkajian teknik hold and spin great rhino megaways capaian finansialanalisis struktur peluang buffalo king algoritma komputasimekanisme sticky wild multiplier the dog house stabilitas hasilimplementasi strategi hammer multiplier power of thor ritme akumulasi Let me Pop up