我在ZStack中应用旋转手势和放大手势。但是ZStack没有旋转,但是ZStack中的图像在手势上旋转和缩放,而我在ZStack上应用了旋转和缩放。
下面是我的代码:
var body: some View {
NavigationView {
VStack {
GeometryReader { geo in
let w = geo.size.width
let h = geo.size.height
let size = getSize(h, w)
if size.width > 0 && size.height > 0 {
ZStack {
Image(uiImage: service.backgroundImage!)
.resizable()
.scaledToFill()
.frame(width: size.width, height: size.height, alignment: .center)
.clipped()
//This is the ZStack --------------------
ZStack{
Image(uiImage: foregroundImage)
.resizable()
.scaledToFit()
.background(GeometryGetter(rect: $imageRect))
}
.rotationEffect(rotationAngle)
.scaleEffect(scale)
.gesture(DragGesture(minimumDistance: 0 , coordinateSpace: .local)
.onChanged { value in
self.offset.x += value.location.x - value.startLocation.x
self.offset.y += value.location.y - value.startLocation.y
print("->> Location - \(value.location)")
})
.offset(x: offset.x, y: offset.y)
.gesture(simultaneous)
.background(.blue)
}
.frame(width: size.width, height: size.height, alignment: .center)
.clipped()
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(AppDefaults.Theme.secondaryColor)
}
}
bottomContainerView()
}
.background(Color.black.ignoresSafeArea())
}
}
1条答案
按热度按时间nlejzf6q1#
在
.rotationEffect(rotationAngle)
之前加上.background(.blue)
。查看swiftUI中的修改器顺序问题。请查看here