动画未在imageView(iOS)上居中
我有一个目标的图像,我试图使用动画来裁剪外环而不调整其大小。我正在使用UIBelzierPath来实现这一点,由于某种原因,我无法将其直接放在图像的中心,因为它只对右下角设置动画,就像直接对imageView设置动画一样。我做错了什么?我努力与动画,所以任何帮助将是美妙的动画未在imageView(iOS)上居中,ios,animation,Ios,Animation,我有一个目标的图像,我试图使用动画来裁剪外环而不调整其大小。我正在使用UIBelzierPath来实现这一点,由于某种原因,我无法将其直接放在图像的中心,因为它只对右下角设置动画,就像直接对imageView设置动画一样。我做错了什么?我努力与动画,所以任何帮助将是美妙的 @IBOutlet weak var image: UIImageView! @IBAction func animate(sender: AnyObject) { animateCollapse() } priv
@IBOutlet weak var image: UIImageView!
@IBAction func animate(sender: AnyObject) {
animateCollapse()
}
private func animateCollapse() {
let view = image
let circleMaskPathInitial = UIBezierPath(ovalInRect: view.frame)
let circleMaskPathFinal = UIBezierPath(ovalInRect: CGRectInset(view.frame, 10 , 10))
performAnimation(circleMaskPathInitial, finalPath: circleMaskPathFinal)
}
private func performAnimation(initialPath: UIBezierPath, finalPath: UIBezierPath) {
let maskLayer = CAShapeLayer()
maskLayer.path = finalPath.CGPath
image.layer.mask = maskLayer
let maskLayerAnimation = CABasicAnimation(keyPath: "path")
maskLayerAnimation.fromValue = initialPath.CGPath
maskLayerAnimation.toValue = finalPath.CGPath
maskLayerAnimation.duration = 1.0
maskLayerAnimation.delegate = self
maskLayer.addAnimation(maskLayerAnimation, forKey: "path")
}
图片:
动画后的图像:尝试将
let circlemaskpathinital=UIBezierPath(ovalInRect:view.frame)
更改为let circlemaskpathinital=UIBezierPath(ovalInRect:view.bounds)
。我的猜测是,您确实希望rect的原点位于图像视图的(0,0),但其帧的原点不是(0,0)。尝试更改let circlemaskpathinital=UIBezierPath(ovalInRect:view.frame)
到let circlemaskpathinital=UIBezierPath(ovalInRect:view.bounds)
。我的猜测是,您确实希望矩形的原点位于图像视图的(0,0),但其帧的原点不是(0,0)。还必须使用边界更新circleMaskPathFinal->UIBezierPath(ovalInRect:CGRectInset(view.bounds,10,10))还必须使用边界->UIBezierPath(ovalInRect:CGRectInset(view.bounds,10,10))更新circleMaskPathFinal