IOS學習 convertPoint的實驗

IOS-- UIView中的座標轉換


// 將像素pointpoint所在視圖轉換到目標視圖view中,返回在目標視圖view中的像素值

- (CGPoint)convertPoint:(CGPoint)point toView:(UIView *)view;

// 將像素pointview中轉換到當前視圖中,返回在當前視圖中的像素值

- (CGPoint)convertPoint:(CGPoint)point fromView:(UIView *)view;


// rectrect所在視圖轉換到目標視圖view中,返回在目標視圖view中的rect

- (CGRect)convertRect:(CGRect)rect toView:(UIView *)view;

// rectview中轉換到當前視圖中,返回在當前視圖中的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的結果是相同的

發佈了17 篇原創文章 · 獲贊 5 · 訪問量 5萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章