views:

24

answers:

1

I'm creating a small UIView of size 320 pixels width and 120 pixels height. I'm using following code to add the view to top most window.

baseview.frame = CGRectMake(0,20,320,120);
UIWindow* window = [[UIApplication sharedApplication] keyWindow];
[window addSubview:baseView];    
[window bringSubviewToFront:baseView];

The above code is showing a view below the status bar and it is as expected. This is working fine when the app's orientation is portrait. But when the app's orientation is inverted portrait, i'm adding one more line of code to rotate the view and that is

[baseView setTransform:CGAffineTransformMakeRotation(-M_PI/2)];

But now, I'm seeing the view at the bottom of the application (instead of seeing at the top below status bar) and the baseview is rotate and appearing properly except the position at the bottom. How should I handled this situation to show the view under the status bar.

A: 

If you add the view in question as a subview to the main view in the window, the rotation and positioning would be taken care of for you.

If you do need to add the view as a subview of the key window, I think you need to tweak the center of the view.

Yannick Compernol
Even I tried setting the center of the view. Still it not working. The problem i'm suspecting is the 0,0 co-ordinates start at top left in portrait mode. even after rotating the device the co-ordinates will have same location. That's why its not changing to top location.
Satyam svv
You can't add the view as subview to the main view? Since that'll solve the issue, besides I rarely need to add a view as subview to the main window.
Yannick Compernol
I agree with you. I'm trying to create my own alert view kind of thing which I want to add to main window. Even if keyboard is appearing, my alert should come above the app. Finally, setting center solved my problem. Thanks for the info
Satyam svv
Indeed, that would be a valid case. Good you've got it solved.
Yannick Compernol
Now I'm facing trouble with other orientations ie landscape. how to decide the center in landscape mode? in inverted portrait mode i'm setting the center as 160,400 and it worked. Cannot understand the co-ordinate calculation.....
Satyam svv