简体   繁体   English

iOS-视图旋转和调整大小

[英]iOS - View rotate and resize

Here is myView 这是myView

这是myView

When 什么时候

self.myView.transform = CGAffineTransformMakeRotation(M_PI*0/180);

[self.myView setFrame:CGRectMake:(self.myView.frame.orgin.x,self.myView.frame.orgin.y,300,self.myView.frame.size.height)];

it will be 这将是

在此处输入图片说明

now when i rotate the view 现在,当我旋转视图时

在此处输入图片说明

And do this again 再做一次

self.myView.transform = CGAffineTransformMakeRotation(M_PI*0/180);

[self.myView setFrame:CGRectMake:(self.myView.frame.orgin.x,self.myView.frame.orgin.y,300,self.myView.frame.size.height)];

在此处输入图片说明

What happened here? 这里发生了什么?

seen like the width is stretched. 看起来像宽度被拉伸了。

Its anyway to fix it or have other way to rotate and resize? 它是要修复它还是有其他旋转和调整大小的方法?

You should use the bounds and center properties to resize and place your view, frame should not be used if the transform property is not the identity transform 您应该使用boundscenter属性来调整视图的大小和位置,如果transform属性不是恒等变换,则不应使用frame

(see warning at the UIView documentation for frame ) (请参阅UIView文档中关于frame的警告)

frame.size is not equal to bounds.size when your view is rotated, if you want your view to have a width of 300, you should set the bounds 旋转视图时frame.size不等于bounds.size ,如果希望视图的宽度为300,则应设置边界

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM