How to make a view which covers whe whole screen, including the status bar?
I want to make an overlay which is partially transparent, and covers the entire screen including the status ba开发者_JS百科r. I've seen that the folks at tapbots do exactly that. So it must be possible somehow. Status bar should still be visible!
Before iPhoneOS 3.2:
[[UIApplication sharedApplication] setStatusBarHidden:YES animated:NO];
after iPhoneOS 3.2:
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation: UIStatusBarAnimationNone];
For more information on these, see the documentation for UIApplication.
There are two ways to hide the status bar:
Programaticaly at runtime by using UIApplication sharedApplication:
- (void)setStatusBarHidden:(BOOL)hiddenwithAnimation:(UIStatusBarAnimation_)animation
Or at design time using the Info.plist property UIStatusBarHidden yes/no value.
You could try creating a full-size view and adding it as a subview of your main window. Something like:
CGRect mainWindowSize = [UIScreen mainScreen].bounds;
UIView* overlay = [[UIView alloc] initWithFrame:mainWindowSize];
// Use colorWithRed:green:blue:alpha: or a solid color then manually tweak alpha
overlay.backgroundColor = [UIColor redColor];
overlay.alpha = 0.2; // transparency level
overlay.userInteractionEnabled = YES;
// Add it on top of the main window
UIWindow* mainWindow = (((MyAppDelegate*)
[UIApplication sharedApplication].delegate).window);
[mainWindow addSubview:overlay];
Caveats: You may have to manually hide the status bar. Also, this overlay view and its subviews are going to get all the user tap events. May want to make sure that's what you want.
push the view controller as a modalViewController....
if your view controller is AVC and assuming you use a navigation controller:
[self presentModalViewController:AVC animated:YES];
from the current view controller you're on.
精彩评论