我实际上是 SwiftUI 的初学者。我想知道是否有办法检测视图的全局位置何时发生变化。目前我可以使用 GeometryReader 获得视图的全局位置,但我绝对无法检测到它何时发生变化。
预先感谢您的帮助 !
struct VideoView: View {
@State var player : AVPlayer // It is a video player
@State var isplaying = false
@State var showcontrols = false // Don't show controls
@State var value : Float = 0
var body: some View {
GeometryReader { geo in
VStack{
ZStack{
VideoPlayer(player: $player)
}
.frame(height: UIScreen.main.bounds.height)
}
.background(Color.black.edgesIgnoringSafeArea(.all))
#IF GLOBAL POSITION OF THIS VIEW IS CHANGING
if(geo.frame(in: .global).midY < 400){
self.player.play()
self.isplaying = true
}
}
#ENDIF
}
}
}