【发布时间】:2017-08-25 10:35:36
【问题描述】:
我正在尝试为 NSImageView 设置动画,使其向下滑动几个点并在执行此操作时淡入。 在搜索了大约几个小时后,我只设法让 alpha 值进行动画处理。 翻译视图有效,但它不是动画的,我不知道为什么。
import Cocoa
class ViewController: NSViewController {
@IBOutlet weak var logo: NSImageView!
@IBAction func doAnimation(_ sender: Any) {
animateLogo()
}
private func animateLogo() {
let top = CATransform3DMakeTranslation(0, 30, 0)
logo.wantsLayer = true
NSAnimationContext.runAnimationGroup({ (context) in
Swift.print("Running animation")
context.duration = 5
logo.animator().alphaValue = 0
logo.layer?.transform = top
}, completionHandler: {
Swift.print("Finished animation")
})
}
}
我在翻译 NSView 时尝试过的另一种方法是
logo.animator().translateOrigin(to: new_origin)
【问题讨论】:
标签: swift animation core-animation appkit