做過幾次有關(guān)UIView坐標(biāo)變換的,但是經(jīng)常不能得到自己想要的效果,今天就把它仔細(xì)研究了下。記下來等以后忘記的時(shí)候再復(fù)習(xí)

重寫shouldAutorateToInterfaceOrientation:,限制某個(gè)方向會(huì)改變?cè)c(diǎn)的位置,原點(diǎn)會(huì)一直保持在左上角,但已經(jīng)不是原來的左上角了
setStatusBarOrientation.改變狀態(tài)欄的方向。它不會(huì)改變?cè)c(diǎn)的位置,但會(huì)改變鍵盤的方向
旋轉(zhuǎn)前self.myview的frame ={0,0,320,50}
CGAffineTransform at =CGAffineTransformMakeRotation(M_PI/2);
[self.myview setTransform:at];
旋轉(zhuǎn)后frame={135,-135,50,320},視圖的所有像素旋轉(zhuǎn)90度
坐標(biāo)是相對(duì)于父視圖的
假如view已經(jīng)轉(zhuǎn)成豎的,這時(shí)通過設(shè)置frame而不是通過setTransform強(qiáng)制成橫的話,會(huì)截掉部分圖像
坐標(biāo)多次變換的合成,要以被變換的view的局部坐標(biāo)系為參照,比如
testView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 50)];
UILabel*label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 20)];
label.text =@"Test";
label.tag=100;
[testView addSubview:label];
此時(shí)的 frame ={0,0,320,50}
UILabel*label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 20)];
label.text =@"Test";
label.tag=100;
[testView addSubview:label];
此時(shí)的 frame ={0,0,320,50}

CGAffineTransform at =CGAffineTransformMakeRotation(M_PI/2);先順時(shí)鐘旋轉(zhuǎn)90
at =CGAffineTransformTranslate(at,200,0);,
[self.testView setTransform:at];
at =CGAffineTransformTranslate(at,200,0);,
[self.testView setTransform:at];

此時(shí)的 frame ={135,65,50,320},可以看到寬高已經(jīng)反過來了,view中的像素方向也改變了,而如果只是用setFrame來改變寬高的話是不會(huì)改變像素方向的