Swift-如何查找正在缩放和旋转的表示层的宽度/高度?

时间:2016-10-24 20:05:01

标签: swift calayer cabasicanimation

所以,我有一个使用CABasicAnimation旋转和缩放的CALayer。由于图层正在旋转,因此帧会返回包含最高到最低x和y值的帧(因此这将大于实际显示的图层)。并且,虽然如果不进行缩放,边界将起作用,但是图层的边界不会。这是我的自定义UIView子类的代码:

func rotateCircleView(duration: CFTimeInterval = 1.0) {
    let rotateAnimation = CABasicAnimation(keyPath: "transform.rotation")
    rotateAnimation.fromValue = 0.0
    rotateAnimation.toValue = CGFloat(M_PI * 2.0)
    rotateAnimation.duration = duration
    rotateAnimation.repeatCount = Float.infinity

    self.layer.addAnimation(rotateAnimation, forKey: rotateKey)
}



func shrinkCircleView(duration: CFTimeInterval = 1.0, to: Double) {


    let from = self.getCurrentAnimationScale()


    let shrinkAnimation = CABasicAnimation(keyPath: "transform.scale")
    shrinkAnimation.additive = true
    shrinkAnimation.fromValue = from - to
    shrinkAnimation.toValue = 0
    shrinkAnimation.duration = duration
    shrinkAnimation.removedOnCompletion = true


    let scaleTransform = CATransform3DMakeScale(CGFloat(to), CGFloat(to), 1.0)
    layer.transform = scaleTransform


    layer.addAnimation(shrinkAnimation, forKey: "shrinkAnimation")

}


func getCurrentAnimationScale() -> Double{

    if let temp = self.layer.presentationLayer(){
        // return scale of presentationLayer

    } else{
        // return scale of self.layer
    }

}

0 个答案:

没有答案