2

I want to work in landscape mode only and so far the only way I can get the appropriate coordinate frame in the rest of the application is by rotating the main window using:

CGAffineTransformMakeRotation(3.1415/2.0f);

which rotates all subviews as well.

It works great, except when I want to draw UILabel, frame rate drops like crazy. I need the truncation and all those pretty things that come with UILabel so my question is, is there a better way of going into landscape mode or speeding up the text drawing. I've seen some applications that work in landscape mode and still have text, so I wonder...

3 Answers3

4

Maybe use CGAffineTransformMakeRotation(M_PI/2.0f); instead? This should produce a truly simple affine transform matrix.

kennytm
  • 510,854
  • 105
  • 1,084
  • 1,005
  • Oh wow that was it, thanks. :) I don't quite understand why though. Doesn't it still multiply out the rest of the elements in the matrix? – Dogan Demir Jan 24 '10 at 08:57
  • 2
    With `M_PI/2.0f` your matrix is something like `[0, 1; -1, 0]`, while with `3.1415/2.0f` (an inaccurate value) you get `[4.6e-5, 0.99…; -0.99…, 4.6e-5]` which cause things very slow. – kennytm Jan 24 '10 at 10:03
2

If all that you want to do is work in landscape mode, as of iPhone OS 2.1 you don't need to apply a transform to your main view. See this answer to this question for more detail.

Community
  • 1
  • 1
Brad Larson
  • 170,088
  • 45
  • 397
  • 571
0

Very Simple:

    myLabel.text = @"Text To Rotate";
    //myLabel is UILabel, which i want to Rotate.
    myLabel.textColor = self.xValuesColor;
    myLabel.backgroundColor = [UIColor redColor];
    myLabel.textAlignment = UITextAlignmentCenter;
    CATransform3D landscapeTransform = CATransform3DIdentity;
    landscapeTransform = CATransform3DRotate(landscapeTransform,-90, 0, 0, 1);
    // -90 is angle to rotate, you can change it according to your requirement. 
    myLabel.layer.transform = landscapeTransform;
    [self addSubview:myLabel];
    [myLabel release];
Sorted
  • 121
  • 1
  • 1