2016-10-28 7 views
1

Swift3に次のアニメーションを変換するには?NSValue valueWithCATransform3D:Swift3内

CABasicAnimation *scaleAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"]; 
scaleAnimation.fromValue = [NSValue valueWithCATransform3D:CATransform3DIdentity]; 
scaleAnimation.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeScale(2.5, 2.5, 1)]; 

私が現在持っていることは

let circleEnlargeAnimation = CABasicAnimation(keyPath: "transform.scale") 
circleEnlargeAnimation.fromValue = CATransform3DIdentity 
circleEnlargeAnimation.toValue = CATransform3DMakeScale(10.0, 10.0, 1.0) 

あるしかし、私のアニメーションが動作していない...次は、フルアニメーションのコードです:

let shapeLayer = CAShapeLayer() 
    let center = CGPoint(x: sampleButton.bounds.width/2.0, y: sampleButton.bounds.height/2.0) 
    let radius = CGFloat(10.0) 

    let path = UIBezierPath(arcCenter: center, radius: radius, startAngle: 0.0, endAngle: (CGFloat(360.0 * M_PI)/180.0), clockwise: true) 
    shapeLayer.path = path.cgPath 
    shapeLayer.fillColor = UIColor.white.cgColor 
    shapeLayer.strokeColor = UIColor.white.cgColor 
    shapeLayer.lineCap = kCALineCapRound 

    shapeLayer.frame = sampleButton.bounds 
    let circleEnlargeAnimation = CABasicAnimation(keyPath: "transform.scale") 
    circleEnlargeAnimation.fromValue = CATransform3DIdentity 
    circleEnlargeAnimation.toValue = CATransform3DMakeScale(10.0, 10.0, 1.0) 
    circleEnlargeAnimation.duration = 1.0 
    shapeLayer.add(circleEnlargeAnimation, forKey: nil) 

    sampleButton.layer.addSublayer(shapeLayer) 

それが唯一のサークルを示すがありますアニメートしないでください。

答えて

3

transform.scaleにはスカラー数値o r transformにマトリックス値を指定します。使用可能なキーの一覧については、Key Value Coding Extensions in Core Animation Programming Guideを参照してください。

あなたがして、インスタンスのための行列値を作成することができます。

NSValue(caTransform3D:CATransform3DMakeScale(10.0, 10.0, 1.0)) 
関連する問題