简体   繁体   中英

iOS - View rotate and resize

Here is 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

(see warning at the UIView documentation for 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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