iOS rotate view around an anchor point and follow touch

前端 未结 1 1577
长情又很酷
长情又很酷 2021-01-14 05:35

I need to create a circular rating meter in iOS, it\'s like a UISlider only curved 3/4 around a circle. I need to rotate a UIImageView (which is the rating needle) around an

相关标签:
1条回答
  • 2021-01-14 06:18

    Have you tried using the anchorPoint property of the UIImageView's underlying layer? If you have a CGPoint representing the point (in your image view's coords) around which it is to rotate, you can set the layer's anchor point:

    CGRect imageBounds = self.needleImageView.bounds;
    [self.needleImageView.layer setAnchorPoint:CGPointMake(rotationPoint.x / imageBounds.size.width, rotationPoint.y / imageBounds.size.height)];
    


    Ensure that the image view's center property is set to the appropriate position also, and then apply the rotation transform to rotate about the layer's anchor point:

    self.needleImageView.transform = CGAffineTransformRotate(self.needleImageView.transform, angleInRadians);
    


    Remember that you need to import <QuartzCore/QuartzCore.h> in order to access the layer's properties.

    0 讨论(0)
提交回复
热议问题