ios座標系轉換

來源:互聯網
上載者:User

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]  CGRect convertRect =  [tableView convertRect:cell.frame toView:self.view];   注意參數的位置,別寫反了。得到了cell相對於self.view的相對座標,那麼cell上控制項相對self.view的座標也就能相應的計算出來了。   還有幾個座標轉換的方法,如下:  [plain]  www.2cto.com- (CGRect)convertRect:(CGRect)rect fromView:(UIView *)view;  - (CGPoint)convertPoint:(CGPoint)point toView:(UIView *)view;  - (CGPoint)convertPoint:(CGPoint)point fromView:(UIView *)view;   用法都大同小異,具體可看文檔。     

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.