iOS状态栏隐藏
在做葡萄相機的時候,使用 項目 info.plist? 文件配置的方法,隱藏了所有的頁面導航欄。但是在做濾鏡選項卡頁面的時候,自定義了一個 視圖。里面有一個 UIWindow 對象。重新指定了根視圖,于是,這個頁面狀態欄又出現了。發現無法用代碼控制隱藏。
#define MOVE_DISTANCE 7@interface EditViewControllerCustomScrollView() {//關閉、確定 按鈕UIButton *cancelButton;UIButton *confirmButton;UIScrollView *filterScrollView; //當前頁面顯示滾動視圖,在當前頁面切換濾鏡效果NSMutableArray *filterImageArr; //保存9 種濾鏡效果數組NSMutableArray *filterTitleArr; //保存9 種濾鏡名稱數組 NSInteger selectedFilter; }@property (nonatomic, assign) CGRect screenRect; //當前屏幕尺寸,兼容橫豎屏幕 @property (nonatomic, strong) UIWindow *window; //彈出 Sheet 所在Window @property (nonatomic, strong) UIView *dimBackground; //彈出后,原來的視圖覆蓋的背景@end@implementation EditViewControllerCustomScrollView#pragma mark - 初始化 //根據滾動視圖需要的數據進行初始化 - (instancetype)initWithFilterImageArray:(NSMutableArray *)filterArray withFilterTitleArray:(NSMutableArray *)nameArray withShowHiddenDelegate:(id<ItemShowHiddenDelegate>)delegateHidden withSelectedDelegate:(id<ItemSelectedDelegate>)delegateSelected andSelectedID:(NSInteger)selectedID {self = [super init];if (self) {////根據橫豎屏幕,獲取當前屏幕尺寸// _screenRect = [UIScreen mainScreen].bounds;if ([[UIDevice currentDevice].systemVersion floatValue] < 7.5 &&UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation)) {_screenRect = CGRectMake(0, 0, _screenRect.size.height, _screenRect.size.width);}filterImageArr = filterArray;filterTitleArr = nameArray;delegateVC = delegateHidden;delegateSelectVC = delegateSelected;selectedFilter = selectedID;////創建新的視圖,用于點擊空白隱藏 sheetView// _dimBackground = [[UIView alloc] initWithFrame:_screenRect];_dimBackground.backgroundColor = [UIColor clearColor];UITapGestureRecognizer *gr = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hidden)];[_dimBackground addGestureRecognizer:gr];////sheetView 本身的背景色// self.backgroundColor = [UIColor colorWithWhite:0.2 alpha:1];/*calculate action sheet frame begin*/CGFloat height = 0.0;//cancel button screenwidth*60height = EIDTVC_BUTTONMENUBAR_HEIGHT+95;/*calculation end*/self.frame = CGRectMake(0, _screenRect.size.height, _screenRect.size.width, height);}return self; }#pragma mark - 顯示隱藏自定義視圖 //always show in a new window - (void)show {//根據當前屏幕尺寸,創建一個新的 Windowself.window = [[UIWindow alloc] initWithFrame:self.screenRect];self.window.windowLevel = UIWindowLevelAlert;self.window.backgroundColor = [UIColor clearColor];//獲取根視圖控制器self.window.rootViewController = [UIViewController new];self.window.rootViewController.view.backgroundColor = [UIColor clearColor];////把發揮作用的兩個視圖都添加到控制器里面// [self.window.rootViewController.view addSubview:self.dimBackground];//確保點擊空白隱藏 SheetView [self.window.rootViewController.view addSubview:self]; //確保 SheetView 可見 self.window.hidden = NO;[self createFilterScrollView];[self createFooterView];[UIView animateWithDuration:0.2 animations:^{//隱藏導航欄 [[UIApplication sharedApplication]setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];self.dimBackground.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.2];self.frame = CGRectMake(0, self.screenRect.size.height-self.frame.size.height, self.frame.size.width, self.frame.size.height);} completion:^(BOOL finished) {}];}- (void)hidden {[UIView animateWithDuration:0.2 animations:^{self.dimBackground.backgroundColor = [UIColor clearColor];self.frame = CGRectMake(0, self.screenRect.size.height, self.frame.size.width, self.frame.size.height);} completion:^(BOOL finished) {self.window = nil;}];////調用代理方法// if(delegateVC!=nil) {[delegateVC itemHidden];} }?
解決辦法:
http://stackoverflow.com/questions/19137559/when-hiding-the-statusbar-my-navigation-bar-moves-up-in-ios7
You can create a custom UIView with its frame as
customView.frame=CGRectMake(0, 20, self.view.frame.size.width, self.view.frame.size.height);Also hide your status bar by following the below steps
Go to info.plist and add two attributes if not present. set "Status bar is initially hidden" to YES and set UIViewControllerBasedStatusBarAppearance to NO. This will hide status bar for your app.
?
?
再配置一個 plist 屬性
?
?
?
?
其他方法
| 1 down vote | Add this code in your view Controller: if ([self respondsToSelector:@selector(setEdgesForExtendedLayout:)]) {self.edgesForExtendedLayout = UIRectEdgeNone; } |
?
| 1 down vote | I had to do this once.. I ended up creating a custom navigation bar of my own and then just set the frame as: navBar.frame=CGRectMake(0, 20, self.view.frame.size.width, self.view.frame.size.height); It worked for me at the time,…just try it out. |
轉載于:https://www.cnblogs.com/allanliu/p/4310534.html
總結
- 上一篇: 配置ip地址四种方法,方便学习linux
- 下一篇: Oracle Proc开发之Makefi