Core Animation rotation around point

后端 未结 2 1567
庸人自扰
庸人自扰 2021-01-06 12:28

I would like to make an IBOutlet rotate around a specific point in the parent view, currently i only know how to rotate it around an anchor point, however, i want to use a p

2条回答
  •  一生所求
    2021-01-06 12:50

    Translated David's answer to swift 3:

        let rotationPoint = CGPoint(x: layer.frame.width / 2.0, y: layer.frame.height / 2.0) // The point we are rotating around
    
        print(rotationPoint.debugDescription)
        let width = layer.frame.width
        let height = layer.frame.height
        let minX = layer.frame.minX
        let minY = layer.frame.minY
    
        let anchorPoint = CGPoint(x: (rotationPoint.x-minX)/width,
                                  y: (rotationPoint.y-minY)/height)
    
        layer.anchorPoint = anchorPoint;
        layer.position = rotationPoint;
    

提交回复
热议问题