ios座標系轉換

2021-06-15 06:21:23 字數 882 閱讀 2242

1.- (cgrect)convertrect:(cgrect)rect toview:(uiview *)view;

文件解釋:converts a rectangle from the receiver』s coordinate system to that of another view.

意思就是說把乙個矩形從接收者的座標系轉換到另乙個檢視(view)的座標系中.

注:若view引數為空,則轉換為視窗(window)的座標系;接收者與view都必須是同一視窗(window)的物件。

eg:下面是把選中的cell單元的frame轉換為相對於當前視窗座標系的座標:

[plain]view plain

copy

cgrect convertrect =  [tableview convertrect:cell.frame toview:self.view];  

注意引數的位置,別寫反了。

得到了cell相對於self.view的相對座標,那麼cell上控制項相對self.view的座標也就能相應的計算出來了。

還有幾個座標轉換的方法,如下:

[plain]view plain

copy

- (cgrect)convertrect:(cgrect)rect fromview:(uiview *)view;  

- (cgpoint)convertpoint:(cgpoint)point toview:(uiview *)view;  

- (cgpoint)convertpoint:(cgpoint)point fromview:(uiview *)view;  

用法都大同小異,具體可看文件。

iOS座標系轉換

把乙個矩形從接收者的座標系轉換到另乙個檢視 view 的座標系中.注 若view引數為空,則轉換為視窗 window 的座標系 接收者與view都必須是同一視窗 window 的物件。下面是把選中的from單元的frame轉換為相對於當前視窗座標系的座標 預設情況下frame是以父控制項 windo...

iOS 轉換座標系

ios中檢視座標系的轉換主要用到uiview的四個api 座標系轉換的實質是 更改座標系的原點.cgpoint convertpoint cgpoint point toview nullable uiview view cgpoint convertpoint cgpoint point from...

iOS座標系轉換總結

座標系轉換方法 cgpoint convertpoint cgpoint point toview nullable uiview view cgpoint convertpoint cgpoint point fromview nullable uiview view cgrect convert...