在超级视图中我有12个子视图,这12个子视图被排列为color wheel之类的轮子。我想在superview的中心周围旋转所有子视图,我从这个站点的其他线程借用代码:
// Set up path movement
let pathAnimation = CAKeyframeAnimation(keyPath: "position")
pathAnimation.calculationMode = kCAAnimationPaced
pathAnimation.fillMode = kCAFillModeForwards
pathAnimation.removedOnCompletion = false
pathAnimation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear)
pathAnimation.duration = 3.0
// Create a circle path
let curvedPath = CGPathCreateMutable()
let circleContainer = CGRectMake(self.colorWheelCenter.x - self.colorWheelRadius, self.colorWheelCenter.y - self.colorWheelRadius, self.colorWheelRadius * 2, self.colorWheelRadius * 2)
CGPathAddEllipseInRect(curvedPath, nil, circleContainer)
// var rotationTransform = CGAffineTransformMakeRotation(CGFloat(2 * PI * 1 / 12))
// CGPathAddEllipseInRect(curvedPath, &rotationTransform, circleContainer)
pathAnimation.path = curvedPath
subview1.layer.addAnimation(pathAnimation, forKey:"myCircleAnimation1")
subview2.layer.addAnimation(pathAnimation, forKey:"myCircleAnimation1")
// and other subview
没问题我可以旋转子视图,但是所有子视图都从位置0度开始,但我希望这12个子视图从它们的原始位置开始并且也以它们的原始位置结束,怎么做呢?我应该在路径中设置初始点吗?怎么样?或者我应该使用transform
?感谢。