做过几次有关UIView坐标变换的,但是经常不能得到自己想要的效果,今天就把它仔细研究了下。记下来等以后忘记的时候再复习

重写shouldAutorateToInterfaceOrientation:,限制某个方向会改变原点的位置,原点会一直保持在左上角,但已经不是原来的左上角了

 

setStatusBarOrientation.改变状态栏的方向。它不会改变原点的位置,但会改变键盘的方向

旋转前self.myviewframe ={0,0,320,50}

CGAffineTransform at =CGAffineTransformMakeRotation(M_PI/2);

[self.myview setTransform:at];

旋转后frame={135,-135,50,320},视图的所有像素旋转90

坐标是相对于父视图的

 

假如view已经转成竖的,这时通过设置frame而不是通过setTransform强制成横的话,会截掉部分图像

 

坐标多次变换的合成,要以被变换的view的局部坐标系为参照,比如

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];
此时的 frame ={0,0,320,50}

UIView的旋转

CGAffineTransform at =CGAffineTransformMakeRotation(M_PI/2);先顺时钟旋转90
at =CGAffineTransformTranslate(at,200,0);,
[self.testView setTransform:at];

UIView的旋转

此时的 frame ={135,65,50,320},可以看到宽高已经反过来了,view中的像素方向也改变了,而如果只是用setFrame来改变宽高的话是不会改变像素方向的





相关文章:

  • 2022-12-23
  • 2021-10-29
  • 2022-12-23
  • 2022-02-07
  • 2022-12-23
  • 2022-12-23
  • 2021-09-13
  • 2021-12-20
猜你喜欢
  • 2021-11-23
  • 2022-12-23
  • 2021-05-12
  • 2022-12-23
  • 2022-12-23
  • 2022-03-03
相关资源
相似解决方案