IOS-- UIView中的座標轉換
// 將像素point由point所在視圖轉換到目標視圖view中,返回在目標視圖view中的像素值
- (CGPoint)convertPoint:(CGPoint)point toView:(UIView *)view;
// 將像素point從view中轉換到當前視圖中,返回在當前視圖中的像素值
- (CGPoint)convertPoint:(CGPoint)point fromView:(UIView *)view;
// 將rect由rect所在視圖轉換到目標視圖view中,返回在目標視圖view中的rect
- (CGRect)convertRect:(CGRect)rect toView:(UIView *)view;
// 將rect從view中轉換到當前視圖中,返回在當前視圖中的rect
- (CGRect)convertRect:(CGRect)rect fromView:(UIView *)view;
其中如果兩個比較對象是有關聯的,比較機制就顯而易見了,但是沒有關聯的時候,系統會默認將兩個對象的跟View放在同一座標系下,進行計算兩個對象的位置。
經過試驗發現,toView和fromView的作用相同,只是參數和調用不同
CGPoint soundPoint = [[self superview] convertPoint:point fromView:self];
CGPoint soundPoint1 = [self convertPoint:point toView:[self superview]];
soundPoint和soundPoint1的結果是相同的