Question

Editing to ask if Autolayout helps in this situation?

How can I have my UILabel maintain a fixed position on screen yet still rotate? shouldAutorotateToInterfaceOrientation is returning YES and the label is rotating just fine, but no matter how I set the struts an springs in Xcode the position of the label changes.

The first image shows how I've created the layout in storyboard, with four individual UILabels. The second image shows how landscape appears -- not what I want. The third image shows how I would like landscape to look, with the rotation animation of each number centered on the number itself.

This is how I've created the layout in storyboard, with four individual UILabels. This is how landscape appears -- not what I want. Here is what I would like landscape to look, with the rotation animation of each number centered on the number itself.

Was it helpful?

Solution

vrk's on the right track with his answer, but shouldAutorotateToInterfaceOrientation: is not the right method in which to lay out your labels. When you receive shouldAutorotateToInterfaceOrientation:, nothing has been updated for the new orientation yet.

You should lay out your views in willAnimateRotationToInterfaceOrientation:duration:. As the documentation states:

By the time this method is called, the interfaceOrientation property is already set to the new orientation, and the bounds of the view have been changed. Thus, you can perform any additional layout required by your views in this method.

You could even animate your views to their new positions in this method.

OTHER TIPS

you could perform a rotation on the labels(transformatin). do that on didrotatefrom interfaceorientation method in uiviewcontroller.

uilabel.transform=CGAffineTransformMakeRotation(M_PI / -4); like this. perform this on all four orientation. and one thing take the statusbar orientation from appdelegate other than device orientation. it will help you keep in sync with view orientation.

you need to set the label's frame position values manually in shouldAutorotateToInterfaceOrientation method

Create two UILabels, one horizontally and other vertically. Hide and show the required Label when you change orientation. To do this, you have to put in viewDidLoad:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didRotate:) name:@"UIDeviceOrientationDidChangeNotification" object:nil];

and implement

- (void) didRotate:(NSNotification *)notification{

       UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];

       if (orientation == UIDeviceOrientationLandscapeLeft)
       {

          // show Horizontal Label
       }
       ....
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top