iOS座標系轉換

2021-07-05 05:58:16 字數 638 閱讀 2430

把乙個矩形從接收者的座標系轉換到另乙個檢視(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;

ios座標系轉換

1.cgrect convertrect cgrect rect toview uiview view 文件解釋 converts a rectangle from the receiver s coordinate system to that of another view.意思就是說把乙個矩形...

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...