Загрузка видео...

Не удалось загрузить видео

На главную

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 просмотров • 1 год назад •via X (Twitter)

Комментарии: 9

Фото профиля Mike Mikina
Mike Mikina1 год назад

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
Harlan Haskins1 год назад

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

Фото профиля Mike Mikina
Mike Mikina1 год назад

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
Raul Menezes1 год назад

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
Mike Mikina1 год назад

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
Pavan1 год назад

Oh I didn’t know this, good one!

Фото профиля Moneky
Moneky1 год назад

Is this Swift for newbies?

Фото профиля Rob Jonson
Rob Jonson1 год назад

How is nil valid as "some Gesture" ??

Фото профиля Mike Mikina
Mike Mikina1 год назад

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

Похожие видео