跳过导航
Remember, you can simply disable the gesture recognizer in SwiftUI using a ternary operator.
0:00 / 0:24

Remember, you can simply disable the gesture recognizer in SwiftUI using a ternary operator.

Mike Mikina

@mikemikina1215 位关注者

在 X 上查看
224 个赞下载原帖

22,491 次观看

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 ➡️

9 条评论

评论来自 X (Twitter) 上的原帖

  • Mike Mikina 的头像

    @mikemikina

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

    7 个赞

  • Harlan Haskins 的头像

    @harlanhaskins

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

    3 个赞

  • Mike Mikina 的头像

    @mikemikina

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

    1 个赞

  • Raul Menezes 的头像

    @rmenezes89

    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.

    1 个赞

  • Mike Mikina 的头像

    @mikemikina

    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 的头像

    @pavm035

    Oh I didn’t know this, good one!

    1 个赞

  • Moneky 的头像

    @wealthybaboon

    Is this Swift for newbies?

  • Rob Jonson 的头像

    @ConfusedVorlon

    How is nil valid as "some Gesture" ??

  • Mike Mikina 的头像

    @mikemikina

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