Так что в моем ContentView.swift у меня есть этот код:
import SwiftUI
extension UIScreen{
static let screenWidth = UIScreen.main.bounds.size.width
static let screenHeight = UIScreen.main.bounds.size.height
static let screenSize = UIScreen.main.bounds.size
}
struct ContentView: View {
@State var Direction: Int = 0
@State var ButtonsShowing: Bool = true
@State var View: Int = 0
func MoveLeft() {
if ButtonsShowing == true {
ButtonsShowing = false
}
}
func MoveRight() {
if ButtonsShowing == true {
ButtonsShowing = false
}
Direction = 1
}
var body: some View {
ZStack {
Image("Space").resizable()
.frame(width: UIScreen.screenWidth, height: UIScreen.screenHeight + 50)
.edgesIgnoringSafeArea(.all)
VStack {
HStack {
Button(action: MoveLeft) {
if ButtonsShowing == true {
NavigationLink(destination: Playing()) {
Image("LeftClick")
.frame(width: UIScreen.screenWidth / 2, height: UIScreen.screenHeight)
}
}
}
Spacer()
Button(action: MoveRight) {
if ButtonsShowing == true {
Image("RightClick")
.frame(width: UIScreen.screenWidth / 2, height: UIScreen.screenHeight)
}
}
}
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
Я получаю предварительный просмотр этого: Предварительный просмотр кнопки с NavigationLink
Если вы посмотрите на мою левую кнопку, я хочу, чтобы она перевела меня на другой взгляд, но не знаю как. У меня есть NavigationLink в нем, с моим назначением, являющимся другим представлением (Playing.swift, если необходимо знать, я называю это с помощью Playing ())
Очевидно, что я делаю что-то не так, и я [ [надеюсь]] точно знаю, что это из кнопки, а не из другого вида:
NavigationLink(destination: Playing()) {
Image("LeftClick")
.frame(width: UIScreen.screenWidth / 2, height: UIScreen.screenHeight)
}
Заранее спасибо.