iOS围绕锚点旋转视图并按照触摸 [英] iOS rotate view around an anchor point and follow touch

查看:449
本文介绍了iOS围绕锚点旋转视图并按照触摸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在iOS中创建一个圆形评级表,它就像一个UISlider只绕圆圈弯曲3/4。我需要在一个锚点附近旋转一个UIImageView(它是一个评级针),通过拖动一个看不见的可触摸手柄区域,它将跟随针尖。针的角度将确定一个值。

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 anchor point, by dragging an invisible touchable handle area the will follow the tip of the needle. The angle of the needle will determine a value.

我很难找到一个优雅的解决方案。有什么想法吗?

I am struggling to find an elegant solution. Any thoughts?

推荐答案

您是否尝试过使用 anchorPoint 属性 UIImageView 的底层?如果你有 CGPoint 表示要旋转的点(在图像视图的坐标中),你可以设置图层的锚点:

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);



请记住,您需要导入< QuartzCore / QuartzCore.h> 以访问图层的属性。

这篇关于iOS围绕锚点旋转视图并按照触摸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆