關於bounds和frame的區別

2022-08-19 03:54:09 字數 944 閱讀 4156

今天測試了乙個關於bounds的demo,發現了之前一直不知道的問題

// do any additional setup after loading the view.

uiview * view=[[uiview alloc]initwithframe:cgrectmake(10, 10, 200, 200)];

view.bounds=cgrectmake(-20, -20, 200, 200);

nslog(@"%f,%f",view.frame.origin.x,view.frame.origin.y);

// view.center=cgpointmake(160, 240);

view.backgroundcolor=[uicolor redcolor];

[self.view addsubview:view];

uiview * l=[[uiview alloc]initwithframe:cgrectmake(0, 0, 100, 100)];

l.backgroundcolor=[uicolor cyancolor];

[view addsubview:l];

**就是這麼多。

1.如果不設定view的frame。而只設定view的bounds,view的預設中心在原點上,也就是左上角。

2.view的bounds的前邊兩個引數是代表本地座標。也就是說如上邊例子中  (-20 ,-20 )代表如view的左上角相對於view 自己的座標,那麼(0,0)就如下圖所示

在self。windows 的座標系中從左上角座標依次是 (0,0) ,(10,10)。。(30,30)

在view自己的本地座標系中,從左上角座標依次是(-20,-20),(0,0);

frame和bounds的區別

現在處於空窗期,有時間去做些工作以外的事情,好久沒有更新部落格了。這會在慢慢的回顧之前學到的ios,回顧一些基礎。這篇文章主要想說下自己對frame和bounds的理解。frame和bounds的區別主要是座標系的區別 frame針對的是父檢視座標系,bounds針對的是自身座標系。bounds的作...

3 關於bounds跟frame區別

翻譯文件上的 bounds是指這個view在它自己座標系的座標和大小 而frame指的是這個view在它superview的座標系的座標和大小 區別主要在座標系這一塊。很明顯乙個是自己為原點的座標系,乙個是以螢幕為原點的座標系。絕對座標。相對座標。比如螢幕旋轉的時候就要以相對來重繪。frame 如果...

關於ios中bounds與frame

1.ios中的bounds是指相對於檢視自己的座標,所以預設view.bounds.origin 0,0 2.ios中的frame是指相對于父檢視的座標 3.當bounds改變的時候,會影響到frame 比如下面的 cgrect frame cgrectmake 0,0,200,200 uilabe...