Last active
April 11, 2024 12:49
-
-
Save benigumocom/25e20dc2659acdf2d6eca7ff8e79734c to your computer and use it in GitHub Desktop.
【SwiftUI】View の overlay は タップイベント を透過できるのか 👉 https://android.benigumo.com/20240411/overlay-event/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
struct TestClickEvent: View { | |
var body: some View { | |
VStack { | |
Button("default") { | |
print("clicked.") // OK | |
} | |
Divider() | |
Button("orange") { | |
print("clicked.") // NG | |
} | |
.overlay { | |
Color.orange | |
} | |
Divider() | |
Button("clear") { | |
print("clicked.") // OK | |
} | |
.overlay { | |
Color.clear | |
} | |
Divider() | |
Button("orange - 0.5") { | |
print("clicked.") // NG | |
} | |
.overlay { | |
Color.orange | |
.opacity(0.5) | |
} | |
Divider() | |
Button("orange - 200x50 - 0.5") { | |
print("clicked.") // OK | |
} | |
.overlay { | |
Color.orange | |
.frame(width: 200, height: 50) | |
.opacity(0.5) | |
} | |
Divider() | |
Button("orange - 200x50 - 0.6") { | |
print("clicked.") // NG | |
} | |
.overlay { | |
Color.orange | |
.frame(width: 200, height: 50) | |
.opacity(0.6) | |
} | |
Divider() | |
Button("orange - 0.5 - 200x50") { | |
print("clicked.") // NG | |
} | |
.overlay { | |
Color.orange | |
.opacity(0.5) | |
.frame(width: 200, height: 50) | |
} | |
} | |
.buttonStyle(.borderedProminent) | |
} | |
} | |
#Preview { | |
TestClickEvent() | |
} |
Author
benigumocom
commented
Apr 11, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment