隐藏和显示导航
第一种做法
注意这里一定要用动画的方式隐藏导航栏,这样在使用滑动返回手势的时候效果最好,和上面动图一致.这样做有一个缺点就是在切换tabBar的时候有一个导航栏向上消失的动画.
- (void)viewWillAppear:(BOOL)animated {
[superviewWillAppear:animated];
[self.navigationController setNavigationBarHidden:YESanimated:YES];
}
- (void)viewWillDisappear:(BOOL)animated {
[superviewWillDisappear:animated];
[self.navigationController setNavigationBarHidden:NOanimated:YES];
}
第二种做法
设置self为导航控制器的代理,实现代理方法,在将要显示控制器中设置导航栏隐藏和显示,使用这种方式不仅完美切合滑动返回手势,同时也解决了切换tabBar的时候,导航栏动态隐藏的问题.
@interfaceWLHomePageController()
@end
@implementationWLHomePageController#pragma
mark - lifeCycle
- (void)viewDidLoad {
[superviewDidLoad];
// 设置导航控制器的代理为
selfself.navigationController.delegate=self;
}
#pragma mark - UINavigationControllerDelegate
// 将要显示控制器
- (void)navigationController:(UINavigationController*)navigationController willShowViewController:(UIViewController*)viewController animated:(BOOL)animated {
// 判断要显示的控制器是否是自己
BOOLisShowHomePage = [viewController isKindOfClass:[selfclass]];
[self.navigationController setNavigationBarHidden:isShowHomePage animated:YES];
}
//提示框
// 初始化对话框
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"用户名或密码错误,请检查后重新登录!" preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[self.navigationController popViewControllerAnimated:YES];
}]];
// 弹出对话框
[self presentViewController:alert animated:true completion:nil];
// 初始化对话框
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"确认注销吗?" preferredStyle:UIAlertControllerStyleAlert];
// 确定注销
UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *_Nonnull action) {
// 1.清除用户名、密码的存储
// 2.跳转到登录界面
[self performSegueWithIdentifier:@"Logout" sender:nil];
}];
UIAlertAction *cancelAction =[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
[alert addAction:okAction];
[alert addAction:cancelAction];
// 弹出对话框
[self presentViewController:alert animated:true completion:nil];
//提示框添加文本输入框
UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"Title" message:@"This is an alert." preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* okAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
//响应事件
//得到文本信息
for(UITextField *text in alert.textFields){
NSLog(@"text = %@", text.text);
}
}];
UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel
handler:^(UIAlertAction * action) {
//响应事件
NSLog(@"action = %@", alert.textFields);
}];
[alert addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.placeholder = @"登录";
}];
[alert addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.placeholder = @"密码";
textField.secureTextEntry = YES;
}];
[alert addAction:okAction];
[alert addAction:cancelAction];
[self presentViewController:alert animated:YES completion:nil];
//显示弹出框列表选择
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Title" message:@"This is an Sheet." preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel
handler:^(UIAlertAction * action) {
//响应事件
NSLog(@"action = %@", action);
}];
UIAlertAction* deleteAction = [UIAlertAction actionWithTitle:@"删除" style:UIAlertActionStyleDestructive
handler:^(UIAlertAction * action) {
//响应事件
NSLog(@"action = %@", action);
}];
UIAlertAction* saveAction = [UIAlertAction actionWithTitle:@"保存" style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
//响应事件
NSLog(@"action = %@", action);
}];
[alert addAction:saveAction];
[alert addAction:cancelAction];
[alert addAction:deleteAction];
[self presentViewController:alert animated:YES completion:nil];
//报警告
//Initializing 'AppDelegate *__strong' with an expression of incompatible type 'id _Nullable'
AppDelegate *app = (AppDelegate *)[UIApplication sharedApplication].delegate;
app.window.rootViewController = app.drawerController;
//xib设置圆角需要到的Key Path:
layer.cornerRadius ,注意该 key 对应 Value 的 type 应该设置为 String
layer.masksToBounds ,注意该 key 对应 Value 的 type 应该设置为 Boolean , 当右侧出现对号时为YES
//这个方法允许你在显示app给用户之前执行最后的初始化操作
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
if (@available(iOS 11.0, *)){//避免滚动视图顶部出现20的空白以及push或者pop的时候页面有一个上移或者下移的异常动画的问题
[[UIScrollView appearance] setContentInsetAdjustmentBehavior:UIScrollViewContentInsetAdjustmentNever];
}
return YES;
}