I am doing:
UIWindow *window = [[[UIApplication sharedApplication] windows] objectAtIndex:0];
CGPoint point = CGPointMake(window.frame.size.width/2, window.frame.size.height/2);
point = CGPointMake(window.frame.size.width - v.frame.size.width - 10, 30);
point = CGPointMake(point.x + offsetLeft, point.y + offsetTop);
v.center = point;
timer1 forMode:NSDefaultRunLoopMode];
[window addSubview:v];
One issue is that when I do in landscape mode:
UIWindow *window = [[[UIApplication sharedApplication] windows] objectAtIndex:0];
and I print:
NSLog(@"WINDOW WIDTH IS %f AND HEIGHT IS %f", window.frame.size.width, window.frame.size.height);
I got:
WINDOW WIDTH IS 768.000000 AND HEIGHT IS 1024.000000
Which is not true.. it seems that it doesn’t care about orientation.
You should not insert views into the
UIWindow. TheUIWindowitself does not rotate. It applies transforms to a rotation subview, which holds the root view. You should be inserting your view into the root view if at all possible. Otherwise, you will need to calculate your own transforms, and that’s a pain.See this question for more details on this issue. The short answer is that this kind of thing is best done by using the View-Based Application template, and making use of the
rootViewControllerto get the root view and insert there.Note that you should also avoid asking for the first window of the
UIApplication. This is not guaranteed to be the “main” window; the first window is the furthest-back window (and it is not unusual for there to be more than one window). If you must use aUIWindow, get it from a view you care about ([view window]), or bind it to yourUIApplicationDelegatein the XIB.