开发者

How to shift item location on screen after iPhone rotation

开发者 https://www.devze.com 2023-01-07 09:26 出处:网络
I have a UILabel that I need to shift up by about 50 pixels on application start (because it starts out in portrait, and I designed it in landscape) and then once again whenever it is put back in port

I have a UILabel that I need to shift up by about 50 pixels on application start (because it starts out in portrait, and I designed it in landscape) and then once again whenever it is put back in portrait. Right now I'm using a CGRect based on its current frame. The problem is when I try to rotate the phone the frame uses the portrait values and it places the label way off. I've tried using a couple other methods, all based around CGRect, and while they kept the label on the right axis, it was shifted all over the place. At the same time I'm doing this, I'm also changing the size of the font, so I think that this might affect something.

The code I used is:

//In ViewDidLoad
CGRect defBox = self.seperator.frame;

//On Rotation to Portriate
CGRect newBox = self.seperator.frame;
  newBox.origin.y += 50;
  self.seperator.frame = ne开发者_开发知识库wBox;

//On Rotation to Landscape
self.seperator.frame = defBox;


Use self.separator.bounds, not self.separator.frame and do it in willAnimateRotationToInterfaceOrientation: or didRotateFromInterfaceOrientation:.

0

精彩评论

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