|
// |
|
// ContentView.swift |
|
// testtest |
|
// |
|
// Created by MC on 2021/2/9. |
|
// |
|
|
|
import SwiftUI |
|
|
|
struct ContentView: View { |
|
|
|
@State var isLeftEditing = false |
|
@State var leftSelection = Set<String>() |
|
|
|
@State var isRightEditing = false |
|
@State var rightSelection = Set<String>() |
|
|
|
var leftNames = ["Karl", "Hans", "Faustao"] |
|
var rightNames = ["1", "2", "3"] |
|
|
|
var body: some View { |
|
NavigationView { |
|
GeometryReader { reader in |
|
HStack { |
|
VStack { |
|
List(leftNames, id: \.self, selection: $leftSelection) { name in |
|
Text(name) |
|
} |
|
.listStyle(PlainListStyle()) |
|
.environment(\.editMode, .constant(self.isLeftEditing ? EditMode.active : EditMode.inactive)).animation(Animation.spring()) |
|
|
|
Button(action: { |
|
self.isLeftEditing.toggle() |
|
}) { |
|
Text(isLeftEditing ? "Done" : "Edit") |
|
.frame(width: 80, height: 40) |
|
} |
|
.background(Color.yellow) |
|
} |
|
.frame(width: reader.size.width * 0.4, height: reader.size.height) |
|
.background(Color.orange) |
|
|
|
VStack { |
|
List(rightNames, id: \.self, selection: $rightSelection) { name in |
|
Text(name) |
|
} |
|
.listStyle(PlainListStyle()) |
|
.environment(\.editMode, .constant(self.isRightEditing ? EditMode.active : EditMode.inactive)).animation(Animation.spring()) |
|
|
|
Button(action: { |
|
self.isRightEditing.toggle() |
|
}) { |
|
Text(isRightEditing ? "Done" : "Edit") |
|
.frame(width: 80, height: 40) |
|
} |
|
.background(Color.yellow) |
|
} |
|
.frame(width: reader.size.width * 0.6, height: reader.size.height) |
|
.background(Color.green) |
|
} |
|
} |
|
.navigationBarTitle("编辑页面", displayMode: .inline) |
|
} |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
struct ContentView_Previews: PreviewProvider { |
|
static var previews: some View { |
|
ContentView() |
|
} |
|
} |