把一个矩形从接收者的坐标系转换到另一个视图(view)的坐标系中.
注:若view参数为空,则转换为窗口(window)的坐标系;接收者与view都必须是同一窗口(window)的对象。
下面是把选中的from单元的frame转换为相对于当前窗口坐标系的坐标:
// 默认情况下frame是以父控件(window)的左上角为坐标原点
CGRec newFrame = [from.superview convertRect:from.frame toView:window];
// CGRec newFrame = [from.superview convertRect:from.bounds toView:window];
还有几个坐标转换的方法,如下:
- (CGRect)convertRect:(CGRect)rect fromView:(UIView *)view;
- (CGPoint)convertPoint:(CGPoint)point toView:(UIView *)view;
- (CGPoint)convertPoint:(CGPoint)point fromView:(UIView *)view;