正在加载视频...

视频加载失败

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:

相关视频