希望你們誰能幫助我,給我建議。
我的任務是用SwiftUI制作一個照片編輯應用程式。 在這個應用程式中,有一個功能是移除一個人的照片的背景(所以只有這個人的物件),然后我創建了一個新的UIImage作為一個圖層,用一個可以移動的影像取代背景(在背景被移除的照片后面),這樣它就被定位了。 當我試圖拖動新的背景時,但我不能,因為被移除背景的相框擋住了新的UIImage背景。
這是我的代碼。
這是我的代碼。
struct MaskImage。View {
@State var currentPositions = CGPoint.init(x。UIScreen.main.bounds.width/2, y: UIScreen.main.bounds.height/4)
@State var currentPosition = CGPoint.init(x。UIScreen.main.bounds.width/2, y: UIScreen.main.bounds.height/4)
@GestureState private var isDragging = false
var body: some View {
GeometryReader { geo in
HStack {
VStack {
Spacer()
ZStack {
Image("EFFECT-1") / DRAGGABLE PHOTO BACKGROUND
.resizable()
.frame(width: abs(geo.size.width-32), height: 375, alignment: .center)
.position(currentPosition)
.手勢(
DragGesture()
.onChanged { value in.
self.currentPosition = value.location
}
. updating($isDragging) { (value, state, transaction) in // 1, 2
state = true
self.currentPosition = value.location
}
)
Image("SEGMENTED_IMAGE_REMOVE_BACKGROUND") //將成為正面的影像。
.resizable()
.frame(width: abs(geo.size.width - 32), height: abs(round((geo.size.width / 2) * 2.438)), alignment: .center)
}
Spacer()
}
}
.background(Color.red)
}
}
}
uj5u.com熱心網友回復:
你可以使用allowsHitTesting來禁用頂部圖片的觸摸互動:
Image("SEGMENTED_IMAGE_REMOVE_BACKGROUND") // The image that will be the front
.resizable()
.frame(width: abs(geo.size.width - 32), height: abs(round((geo.size.width / 2) * 2.438) ), alignment: .center)
.allowedHitTesting(false)
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/321918.html
標籤:
上一篇:Bootstrap:容器內有兩列,但其中一列應打破容器
下一篇:如何為一個只獲取的屬性賦值
