作者:手机用户2502923227 | 来源:互联网 | 2023-09-12 16:12
使用垂直和水平滚动时,无法在图像中看到左上角。
但同时,右下角后还有一些空间。
如何解决?
struct TestView: View {
var body: some View {
VStack(alignment: .leading) {
ScrollView([.horizontal,.vertical]) {
Image(systemName: "keyboard")
.resizable()
.frame(width: 500.0,height: 500.0)
}.frame(width: 300.0,height: 300.0)
}
}
}
您只需为滚动视图的内容添加偏移量
var body: some View {
VStack(alignment: .leading) {
ScrollView([.horizontal,.vertical]) {
Image(systemName: "keyboard")
.resizable()
.frame(width: 500.0,height: 500.0).offset(x: 100,y: 100)
}.frame(width: 300.0,height: 300.0)
}
}
,
关于
struct TestView: View {
var body: some View {
ScrollView([.horizontal,.vertical]) {
VStack {
Spacer(minLength: 200)
HStack {
Spacer(minLength: 200)
Image(systemName: "keyboard")
.resizable()
.frame(width: 300.0,height: 300.0)
}
}
}
.frame(width: 300.0,height: 300.0)
}
}