开发者

Rotating a UIView through the "transform" property gets messed up when the orientation changes

I'm trying to create an iPad application but am encountering a questionable behavior from the simulator (Can't be tested on a device for now..).

The issue is when having any UIView rotate through its transform property, and then allowing the view containing it to be manipulated by changing the orientation of the iPad. This can be simplified by creating a new View-based iPad project and inserting the following code to the view controller:

- (IBAction) rotate:(UIView*)sender {
 if (CGAffineTransformIsIdentity(sender.transform)) {
  sender.transform = CGAffineTransformMakeRotation(M_PI / 4);
 } else {
  sender.transform = CGAffineTransformIdentity;
 }
}

Then adding a single button to the view and linking its action with the above method.

As you see, the method should rotate the button when clicked, and then un-rotate when clicked again - and it does just that. However, when the button is rotated, and you change the orientation (from the Hardware menu), it'll start acting really weird - changing its shape or disappearing altogether.

Worth noting that if I create a translation transform, this does not happen.

My question is:

1. Since I don't have an iPad at the moment (working on that), can anyone tell me if that happens on the device as well? 2. Am I doing something wrong here? Maybe this is not the way to rotate the UIView? If so, what is?

Update: From the documentation, it seems that If [the transform] property is not the identity transform, the value of the frame property is undefined and therefore should be ignored. S开发者_开发百科o the problem is probably the fact that I am using the autoresizeMask while changing the transform property. So how can or should this be done?

Thanks, Aviad.


I think if I remember correctly I ran into this same problem a while back and it was caused by anchors being set in Interface Builder. Go into the Size Inspector and turn off the pins that pin the view to the edges in the authorising panel I think that should do it.

I hope I am remembering this correctly.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜