Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top