Last active
November 23, 2019 12:15
-
-
Save a-v-ershov/387909bb554013de41d10ec66d3f3d06 to your computer and use it in GitHub Desktop.
Пример LongPressGesture
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 LongPressGestureExample: View { | |
@State var rectangleColor = Color(.green) | |
var body: some View { | |
// Создаем LongPressGesture | |
// Жест будет срабатывать только если нажатие длилось как минимум 2 секунды | |
let longPressGesture = LongPressGesture(minimumDuration: 2, maximumDistance: 10) | |
.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(longPressGesture) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment