如何动态地改变NSSlider值,使其看起来是连续的?我尝试使用NSAnimation上下文
private func moveSlider(videoTime: VLCTime) {
DispatchQueue.main.async { [weak self] in
NSAnimationContext.beginGrouping()
NSAnimationContext.current.duration = 1
self?.playerControls.seekSlider.animator().intValue = videoTime.intValue
NSAnimationContext.endGrouping()
}
}我的NSSlider仍然不能顺利运行。
为了把你放进照片里,我正试着制作一个视频播放器,它使用NSSlider来擦拭整个电影。随着视频的继续,滑块也应该移动。就像我说的,它确实动了,但我不能让它平稳地移动。
发布于 2019-01-20 08:44:43
目标-C中有一个苹果示例代码,用于您所要寻找的内容。下面是斯威夫特的样子。
基本上,您需要在NSSlider上进行扩展
extension NSSlider {
override open class func defaultAnimation(forKey key: NSAnimatablePropertyKey) -> Any?{
if key == "floatValue"{
return CABasicAnimation()
}else {
return super.defaultAnimation(forKey: key)
}
}
}然后你可以简单地在你的移动滑块函数中使用这样的东西。
private func moveSlider(videoTime: Float) {
NSAnimationContext.beginGrouping()
NSAnimationContext.current.duration = 0.5
slider.animator().floatValue = videoTime
NSAnimationContext.endGrouping()
}https://stackoverflow.com/questions/54245295
复制相似问题