【发布时间】:2018-04-02 22:08:15
【问题描述】:
Swift 4、macOS 10.13
我已经阅读了关于 SO 的各种答案,但仍然无法让 NSImageView 在其中心而不是其中一个角落旋转。
现在,图像看起来像这样(视频):http://d.pr/v/kwiuwS
这是我的代码:
//`loader` is an NSImageView on my storyboard positioned with auto layout
loader.wantsLayer = true
let oldFrame = loader.layer?.frame
loader.layer?.anchorPoint = CGPoint(x: 0.5, y: 0.5)
loader.layer?.position = CGPoint(x: 0.5, y: 0.5)
loader.layer?.frame = oldFrame!
let rotateAnimation = CABasicAnimation(keyPath: "transform.rotation")
rotateAnimation.fromValue = 0.0
rotateAnimation.toValue = CGFloat(-1 * .pi * 2.0)
rotateAnimation.duration = 2
rotateAnimation.repeatCount = .infinity
loader.layer?.add(rotateAnimation, forKey: nil)
任何想法我仍然缺少什么?
【问题讨论】:
-
您找到解决方案了吗?
-
@Roee84 不,我想我最终放弃了。 :)
-
LOL :) 如果我找到什么我会更新
-
@CliftonLabrum 我更新了我的答案,现在应该可以了。
-
我说我会更新 - @CliftonLabrum 答案效果很好,只需确保在“ViewWill...”或“ViewDid...”函数之外编写此内容
标签: cocoa cabasicanimation nsimageview