我有一個 CABasicAnimation 移動一個 NSHostingView (它是一個滾動字幕文本)。當用戶將滑鼠游標移到視圖上時,影片必須停止并且可以與視圖互動。
我嘗試了以下方法:
方法 1:
按照 Apple 檔案的建議(https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/CoreAnimation_guide/AdvancedAnimationTricks/AdvancedAnimationTricks.html#//apple_ref/doc/uid/TP40004514-CH8-SW14 ),我嘗試使用 convertTime / speed = 0 實作暫停/恢復方法。
它有效,影片暫停并恢復,但是當影片暫停時,視圖內的用戶 clic 坐標是其中之一模型層而不是表示層之一。因此,如果用戶沒有影片,點擊會回應用戶點擊的位置。
方法2:
我嘗試了我的各種影片標志CABasicAnimation如下:
let animation = CABasicAnimation(keyPath: "position");
animation.duration = 10
animation.fromValue = [0, self.frame.origin.y]
animation.toValue = [-500, self.frame.origin.y]
animation.isCumulative = true
animation.isRemovedOnCompletion = false
animation.fillMode = .forwards
不管我使用什么,當影片被洗掉時,視圖會回到原來的位置(它會跳回到原來的位置)。
方法3:
我嘗試通過讀取表示層位置來保存當前影片值,然后再洗掉,如下所示:
print("before")
let currentPosition = layer.presentation()?.position
print("after")
但是這個方法永遠不會回傳!(即“之后”從不列印)。它可能是一個錯誤或什么?
我現在想不通了。如果有人有建議,那將有很大幫助。謝謝!
uj5u.com熱心網友回復:
訪問layer?.presentation()?.position不起作用,因為animation.fromValue并且animation.toValue應該是CGPoint值:
animation.fromValue = CGPoint(x: 0, y: self.frame.origin.y)
animation.toValue = CGPoint(x: -500, y: self.frame.origin.y)
然后方法 3 作業得很好。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/438390.html
上一篇:pygame:精靈的動作沒有改變
下一篇:Swiftui串列影片
