如何在其轴上旋转形状?

时间:2015-07-05 14:03:28

标签: ios swift

六边形旋转,但它不会留在原位并旋转。每次单击按钮时,我需要更改它才能顺时针旋转一次。

    shape6 = CAShapeLayer()
    view.layer.addSublayer(shape6)
    shape6.opacity = 0.5
    shape6.lineWidth = 2
    shape6.lineJoin = kCALineJoinMiter
    shape6.strokeColor = UIColor(hue: 0.786, saturation: 0.79, brightness: 0.53, alpha: 1.0).CGColor
    shape6.fillColor = UIColor(hue: 0, saturation: 0, brightness: 0, alpha: 0).CGColor

    path6 = UIBezierPath()
    path6.moveToPoint(CGPointMake(35,430))
    path6.addLineToPoint(CGPointMake(80, 300))
    path6.closePath()
    shape6.path = path6.CGPath


@IBAction func ispin(sender: AnyObject) {
    UIView.animateWithDuration(1.0, animations: ({
        self.shape1.transform = CATransform3DMakeRotation(30, 150, 400, 20)
        self.shape2.transform = CATransform3DMakeRotation(30, 150, 400, 20)
        self.shape3.transform = CATransform3DMakeRotation(30, 150, 400, 20)
        self.shape4.transform = CATransform3DMakeRotation(30, 150, 400, 20)
        self.shape5.transform = CATransform3DMakeRotation(30, 150, 400, 20)
        self.shape6.transform = CATransform3DMakeRotation(30, 150, 400, 20)
    }))

}

1 个答案:

答案 0 :(得分:0)

尝试设置形状shape6的锚点:

shape6.anchorPoint = CGPointMake(0.5, 0.5)