Video wird geladen...

Video konnte nicht geladen werden

Zur Startseite

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 Aufrufe • vor 1 Jahr •via X (Twitter)

9 Kommentare

Profilbild von Mike Mikina
Mike Mikinavor 1 Jahr

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

Profilbild von Harlan Haskins
Harlan Haskinsvor 1 Jahr

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

Profilbild von Mike Mikina
Mike Mikinavor 1 Jahr

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

Profilbild von Raul Menezes
Raul Menezesvor 1 Jahr

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.

Profilbild von Mike Mikina
Mike Mikinavor 1 Jahr

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.

Profilbild von Pavan
Pavanvor 1 Jahr

Oh I didn’t know this, good one!

Profilbild von Moneky
Monekyvor 1 Jahr

Is this Swift for newbies?

Profilbild von Rob Jonson
Rob Jonsonvor 1 Jahr

How is nil valid as "some Gesture" ??

Profilbild von Mike Mikina
Mike Mikinavor 1 Jahr

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

Ähnliche Videos