我正在尝试放大图像,以使包含的框也被调整大小,并在其下方按下标题。 它位于滚动视图中,因此可以在放大状态下平移图像。 下面的一半代码可以正常工作,但是不能像在滚动视图中那样拖动图像。 另外,HStack在左侧被剪裁,而右侧则留有空隙。
struct ImageView: View {
@State var scale = CGFloat(1.0)
@State var lastScaleValue: CGFloat = 1
@State var frameWidth: CGFloat = 0
@State var imageSize: CGFloat = 1
@State private var selection = 0
var body: some View {
GeometryReader { geometry in
ScrollView(){ //Scrollview for page
ScrollView([.horizontal, .vertical]){//Scrollview for image
HStack{
Image(uiImage: ImageSet.getImage(1))
.resizable()
// .scaledToFit()
// .aspectRatio(1, contentMode: .fit)
.scaleEffect(self.lastScaleValue)
.gesture(MagnificationGesture().onChanged { val in
if val <= 1 {
self.frameWidth = geometry.size.width
}
else{
self.frameWidth = geometry.size.width * val
}
print("Parent Width: \(geometry.size.width)")
print("Scale: \(val)")
print("Frame Width: \(self.frameWidth)")
}
)
.frame(minWidth: 0, maxWidth: .infinity,minHeight: 0,maxHeight: .infinity)
}
.padding(0)
.frame(minWidth: 0, maxWidth: self.frameWidth, minHeight: 0, maxHeight: self.frameWidth)
.background(Color.green)
}
.frame(minWidth: 0, maxWidth: geometry.size.width, minHeight: 0, maxHeight: self.frameWidth)
.background(Color.yellow)
Text("Text pushed down in resizing")
Text("Text pushed down in resizing")
}
.onAppear {
UITableView.appearance().separatorStyle = .none
self.frameWidth = geometry.size.width
}
.navigationBarTitle(Text(self.horoscope.firstname), displayMode: .inline)
}