Last active
November 23, 2019 12:14
-
-
Save a-v-ershov/f9b6d34e9b78bb683172313598c63b3a to your computer and use it in GitHub Desktop.
Пример TapGesture
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
struct TapGestureExample: View { | |
@State var rectangleColor = Color(.green) | |
var body: some View { | |
// Создаем TapGesture | |
// Для обработки используем метод onEnded, который выполняется после завершения тапа | |
let tapGesture = TapGesture().onEnded { _ in | |
if self.rectangleColor == .red { | |
self.rectangleColor = .green | |
} else { | |
self.rectangleColor = .red | |
} | |
} | |
return Rectangle() | |
// Изменяем цвет прямоугольника | |
.foregroundColor(rectangleColor) | |
.cornerRadius(40) | |
.frame(width: 200, height: 100, alignment: .center) | |
// Добавляем gesture к view | |
.gesture(tapGesture) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment