UIWindow

From iPhone Development Wiki
Jump to: navigation, search

UIWindow is a specialized UIView that represents a root node in the view hierarchy. There may be multiple UIWindows.

Non-rectangular windows

Signature -(BOOL)acceptsGlobalPoint:(CGPoint)point;
Available in 2.0 – 3.1

By default UIWindows are rectangular. While you may modify the interaction shape of a UIView by overriding -pointInside:withEvent:, this method will be ignored in UIWindow. Instead, there is an undocumented method -acceptsGlobalPoint: that does this job:

@interface MyWindow : UIWindow { ... }
-(BOOL)acceptsGlobalPoint:(CGPoint)pt;
@end
 
@implementation MyWindow
// Makes the window interacts like a circle.
-(BOOL)acceptsGlobalPoint:(CGPoint)pt {
  CGFloat dx = pt.x - 160, dy = pt.y - 240;
  return (dx*dx+dy*dy <= 100*100);
}
@end

The global point is always in portrait coordinate.

Getting an array of all windows

You can use the following class method to get an array of all windows.

Signature + (NSArray *)allWindowsIncludingInternalWindows:(BOOL)internal onlyVisibleWindows:(BOOL)visible;
Available in 4.0 –
NSArray *windows = [UIWindow allWindowsIncludingInternalWindows:YES onlyVisibleWindows:NO];


References