美文网首页
基本控件

基本控件

作者: 软工官博 | 来源:发表于2018-02-05 15:32 被阅读67次

隐藏和显示导航

第一种做法

-注意这里一定要用动画的方式隐藏导航栏,这样在使用滑动返回手势的时候效果最好,和上面动图一致.这样做有一个缺点就是在切换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

iOS11隐藏导航条后顶部有20单位的空白或者pop页面时明显感觉前一个页面有上移的异常动画的解决办法

//这个方法允许你在显示app给用户之前执行最后的初始化操作
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

if (@available(iOS 11.0, *)){//避免滚动视图顶部出现20的空白以及push或者pop的时候页面有一个上移或者下移的异常动画的问题

        [[UIScrollView appearance] setContentInsetAdjustmentBehavior:UIScrollViewContentInsetAdjustmentNever];

    }

    return YES;

}

相关文章

  • 基本控件

    隐藏和显示导航 第一种做法 -注意这里一定要用动画的方式隐藏导航栏,这样在使用滑动返回手势的时候效果最好,和上面动...

  • 基本控件

    EditText 文本编辑框 inputType属性number:只能输入数字类型phone:只能输入电话键盘的按...

  • 基本控件

    隐藏和显示导航 第一种做法注意这里一定要用动画的方式隐藏导航栏,这样在使用滑动返回手势的时候效果最好,和上面动图一...

  • 基本控件

    Android 中基本控件的用法:一般用法:加id,长宽,加各自需要的属性目录 1,View2,textview-...

  • [Android] 列表控件(RecycleView,GridV

    [TOC]列表控件也算是很常见的控件了,现在基本都切换到RecycleView了,这边记录下列表控件的基本的使用以...

  • iOS - 基本控件

    1,iOS之UILabel详解计算lable的size 2,iOS-UIButton 全面解析 3,iOS-UII...

  • 基本控件拓展

    1,TextView Span的用法 spanSpannableStringBuilder ssb = new S...

  • UGUI基本控件

    UGUI的创建 注意:新建UI时会自动生成Canvas建的控件都是Canvas的子物体 点击GaneObject列...

  • Android基本控件

    基本控件 文本框(TextView) android: text = "..." 设置文本框要显示的内容。默认的情...

  • 1、基本控件

    0、创建HelloWorld工程,在ViewController.m文件 文本控件UILabel 在//设置背景色...

网友评论

      本文标题:基本控件

      本文链接:https://www.haomeiwen.com/subject/vifizxtx.html