ビューが非表示のアニメーションを作成しようとしています。最初は、画面上のあるポイント(たとえば150)から開始し、画面全体に収まるまで拡大します。ここでは、私がこのスニペットでの問題は、それが円のサイズが大きな成長作るのではなく、画面に移動するように小さな円を引き起こすことがあるCABasicAnimation circle CAShapeLayerがスケーリングの代わりにマップを移動する
public func testAnimation(anchor : CGRect){
self.isHidden = false
let mask = CAShapeLayer()
let radius = 15
mask.path = UIBezierPath(roundedRect: CGRect(x: 150,y: 150, width: Double(radius), height: Double(radius)), cornerRadius: CGFloat(radius/2)).cgPath
mask.position = CGPoint(x: 150,y: 150)
mask.fillColor = UIColor.blue.cgColor
self.layer.mask = mask
let oldBounds = mask.bounds
let newBounds = CGRect.init(x: 150,y: 150,width: 1600,height: 1600)
let revealAnimation = CABasicAnimation(keyPath: "bounds")
revealAnimation.fromValue = NSValue(cgRect: oldBounds)
revealAnimation.toValue = NSValue(cgRect: newBounds)
revealAnimation.duration = 5
//Keep the bounds after the animation completes.
mask.bounds = newBounds
mask.add(revealAnimation, forKey: "revealAnimation")
}
を試してみたものです。私はここに見つかったコードを使用しました:http://blog.ericd.net/2015/10/22/swift-animating-a-mask-for-a-uiview/(showUnderView関数)とそれは魅力的なように働いた。私は円の効果を得るためにCALayerをCAShapeLayerに入れ替えましたが、うまくいきません。
私はどのようにしてポジションを安定させることができますか? Iこの 'せfinalPosition =するCGPoint(X:150、Y:150)試み せanimAnim = CABasicAnimation(キーパス: "位置") animAnim.toValue = finalPosition animAnim.duration = 5 マスク.add(animAnim、forKey:nil) ' でもサークルはまだ画面上を移動しています –
初期位置は既にCGPoint(x:150、y:150)ですので、最終位置をあなたの形は同じ場所にとどまります。 最後の位置= CGPoint(x:currentCenter.x - 1600/2、y:currentCenter.y - 1600/2)をcurrentCenter = CGPoint(x:150 + radius/2、y:150 + radius/2) –