SwiftUI: 無描画部分をタップ可能にする方法

p0dee
1 min readMay 26, 2020

--

UIKitでは考えられなかったことだが、SwiftUIではあるビューの無描画部分がタップを検知しない場合がある。

例えば以下では、枠線とラベルだけを描画したボタンなのだが、同じ枠線の内側とは言えども、ラベル上や枠線上はタップ可能である一方で、その他の無描画領域はタップに反応しないことが確認できる。

ビュー内のどの領域もタップ可能にするには、以下のようにcontentShapeを明示する。

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

No responses yet

Write a response