开发者

CGPoints and UIViews

Is it possible to place a CGPoint inside of a UIView as a subview so 开发者_如何学编程that when I rotate my UIView, the CGPoint rotates with it.


A CGPoint is a logical construct, not a graphical. With that said, the following will produce a point rotated around another (called point). This may not apply directly, but should give you some direction. The key is CGAffineTransform.

CGAffineTransform translateTransform = CGAffineTransformMakeTransation(point.x, point.y);
CGAffineTransform rotateTransform = CGAffineTransformMakeRotation(angle);
CGAffineTransform customTransform = CGAffineTransformConcat(CGAffineTransformConcat( CGAffineTransformInvert(translateTransform), rotateTransform), translateTransform);
newPoint = CGPointApplyAffineTransform(initialPoint, customTransform);


CGPoint (like CGSize or CGRect) are C structures and are not supposed to be "drawable". I mean that they are just math representation of coordinates or geometric "stuff" then is not possibile to append them in your display tree.

If you need to display a "point" into your UIView and you need to control it, just add a child UIView to your parent UIView having a frame of 1px square with a color background (if you need to display it). In this case any spatial modification to your parent UIView will affect the child UIView (even rotation).

Otherwise, if you need to know the position of a CGPoint rotate by an angle relative to another point, please refer to this nice answer that contains the math you need.

Rotate a point by another point in 2D

Ciao!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜