Video yükleniyor...

Video Yüklenemedi

Ana Sayfaya Dön

Remember, you can simply disable the gesture recognizer in SwiftUI using a ternary operator. You may need to refactor your gesture recognizer, but it’s quite simple ➡️

22,444 görüntüleme • 1 yıl önce •via X (Twitter)

9 Yorum

Mike Mikina profil fotoğrafı
Mike Mikina1 yıl önce

A follow up! It turns out that the documentation includes gesture(_:isEnabled:), so you can simply pass a boolean value there. Kudos to @harlanhaskins!

Harlan Haskins profil fotoğrafı
Harlan Haskins1 yıl önce

.gesture(…) also has a variant that takes an isEnabled parameter.

Mike Mikina profil fotoğrafı
Mike Mikina1 yıl önce

Wait, what?! How did I miss it? I swear I was looking for it in the documentation the other day 😄 Thanks for sharing! 🙌

Raul Menezes profil fotoğrafı
Raul Menezes1 yıl önce

You can achieve the same result by using `.disabled(!isActive)` so you don’t need to touch your gestures and keep your code as simple as it can be.

Mike Mikina profil fotoğrafı
Mike Mikina1 yıl önce

In this example, it will certainly work the same way. However, if you have another gesture recognizer or the view has additional interactions, it will not work.

Pavan profil fotoğrafı
Pavan1 yıl önce

Oh I didn’t know this, good one!

Moneky profil fotoğrafı
Moneky1 yıl önce

Is this Swift for newbies?

Rob Jonson profil fotoğrafı
Rob Jonson1 yıl önce

How is nil valid as "some Gesture" ??

Mike Mikina profil fotoğrafı
Mike Mikina1 yıl önce

It's because Optional conditionally conforms to Gesture. You can read more about it here:

Benzer Videolar