zoukankan      html  css  js  c++  java
  • UI基础知识

    1、延迟操作:

    [self performSelector:@selector(nextQuestion) withObject:nil afterDelay:0.5];
    2、创建控制器系统会先调initWithNibName方法
    3、storyboard创建控制器
    UIViewController *vc = [storyboard instantiateInitialViewController];

    MJTwoViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@“pink"];

    4、视图生命周期的一些方法:

    didMoveToSuperview
            didAddSubview
            layoutSubviews
    5、  // 1.开始动画

        [UIView beginAnimations:nil context:nil];

        // 动画持续2秒

        [UIView setAnimationDuration:2.0];

         [UIView commitAnimations];

    // 2.动画

        [UIView animateWithDuration:0.5 animations:^{

            label.alpha = 0.5;

        } completion:^(BOOL finished) {

            [UIView animateWithDuration:0.5 delay:0.5 options:UIViewAnimationOptionCurveLinear animations:^{

                label.alpha = 0.0;

            } completion:^(BOOL finished) {

                [label removeFromSuperview];

            }];

        }];

    6、创建cell

    如果cell是通过storyboard或者xib创建的,就不可能会调用initWithStyle,而是调用awakeFromNib

    这个方法来初始化cell

     如果cell是通过手写代码创建,才会调用initWithStyle

    这个方法来初始化cell

    7、// 跳转 -- 执行login2contacts这个segue

            [self performSegueWithIdentifier:@“login2contacts” sender:nil];

         //跳转之前会调用

    - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender

    8、ActionSheet:

    UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"确定要注销?" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"确定" otherButtonTitles:nil, nil];

     [sheet showInView:self.view];

    9、通知

    // 监听通知

        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textChange) name:UITextFieldTextDidChangeNotification object:self.nameField];

    //移除通知

    [[NSNotificationCenter defaultCenter] removeObserver:self];

    10、文档路径

    // 1.获得沙盒根路径

        NSString *home = NSHomeDirectory();

    // 2.document路径

        NSString *docPath = [home stringByAppendingPathComponent:@“Documents"];

    11、偏好设置

    1 -> 保存数据

    // 1.获得沙盒根路径

        NSString *home = NSHomeDirectory();

    // 2.document路径

        NSString *docPath = [home stringByAppendingPathComponent:@“Documents”];

    // 3.立刻同步

      [defaults synchronize];

    2 ->读取数据

    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

    NSString *account = [defaults objectForKey:@"account"];

    BOOL autoLogin = [defaults boolForKey:@“auto_login"];

    12、对象归档

    1 ->controller:

    // 1.归档模型对象

        // 1.1.获得Documents的全路径

        NSString *doc = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];

        // 1.2.获得文件的全路径

        NSString *path = [doc stringByAppendingPathComponent:@"stu.data"];

        // 1.3.将对象归档

        [NSKeyedArchiver archiveRootObject:stu toFile:path];

    // 2.读取归档模型对象

    // 1.1获得Documents的全路径

        NSString *doc = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];

        // 1.2获得文件的全路径

        NSString *path = [doc stringByAppendingPathComponent:@"stu.data"];

        // 1.3从文件中读取MJStudent对象

        Student *stu = [NSKeyedUnarchiver unarchiveObjectWithFile:path];

    2 ->student类:遵守<NSCoding>协议

    实现两个协议方法:/**

     *  将某个对象写入文件时会调用

     *  在这个方法中说清楚哪些属性需要存储

     */

    - (void)encodeWithCoder:(NSCoder *)encoder

    {

        [encoder encodeObject:self.no forKey:@"no"];

        [encoder encodeInt:self.age forKey:@"age"];

        [encoder encodeDouble:self.height forKey:@"height"];

    }

    /**

     *  从文件中解析对象时会调用

     *  在这个方法中说清楚哪些属性需要存储

     */

    - (id)initWithCoder:(NSCoder *)decoder

    {

        if (self = [super init]) {

            // 读取文件的内容

            self.no = [decoder decodeObjectForKey:@"no"];

            self.age = [decoder decodeIntForKey:@"age"];

            self.height = [decoder decodeDoubleForKey:@"height"];

        }

        return self;

    }

    13、读取xib

    // 读取xib文件(会创建xib中的描述的所有对象,并且按顺序放到数组中返回)

        NSArray *objs = [bundle loadNibNamed:@“MJAppView" owner:nil options:nil];

    14、label.layer.cornerRadius = 5;

           label.clipsToBounds = YES;

    表格不允许选中

    self.tableView.allowsSelection = NO;

    表格自动滚动表格到最后一行

        NSIndexPath *lastPath = [NSIndexPath indexPathForRow:self.messageFrames.count - 1 inSection:0];

        [self.tableView scrollToRowAtIndexPath:lastPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];

    15、键盘处理

    /*

     UIKeyboardAnimationCurveUserInfoKey = 7;  // 动画的执行节奏(速度)

     UIKeyboardAnimationDurationUserInfoKey = "0.25"; // 键盘弹出隐藏动画所需要的时间

     UIKeyboardBoundsUserInfoKey = "NSRect: {{0, 0}, {320, 216}}";

     UIKeyboardCenterBeginUserInfoKey = "NSPoint: {160, 588}";

     UIKeyboardCenterEndUserInfoKey = "NSPoint: {160, 372}";

     UIKeyboardFrameChangedByUserInteraction = 0;

     // 键盘弹出

     UIKeyboardFrameBeginUserInfoKey = "NSRect: {{0, 480}, {320, 216}}";// 键盘刚出来那一刻的frame

     UIKeyboardFrameEndUserInfoKey = "NSRect: {{0, 264}, {320, 216}}"; //  键盘显示完毕后的frame

     // 键盘隐藏

     UIKeyboardFrameBeginUserInfoKey = "NSRect: {{0, 264}, {320, 216}}";

     UIKeyboardFrameEndUserInfoKey = "NSRect: {{0, 480}, {320, 216}}";

     */

    16、旋转事件 —> UIApplication —> UIWindow

    17、scrollView相关属性
    1、滚动范围:self.scrollView.contentSize = CGSizeMake(0, contentH);
    2、// 增加额外的滚动区域(在顶部增加64的区域,在底部增加44的区域)

        self.scrollView.contentInset = UIEdgeInsetsMake(64, 0, 44, 0);

    3、// 设置一开始的滚动位置(往下滚动64)

        self.scrollView.contentOffset = CGPointMake(0, -64);

    4、// 设置最大和最小的缩放比例

        self.scrollView.maximumZoomScale = 2.0;

        self.scrollView.minimumZoomScale = 0.2;

    18、alertView    // 弹框

        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"数据展示" message:nil delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];

        // 设置对话框的类型

        alert.alertViewStyle = UIAlertViewStylePlainTextInput;

        // 取得唯一的那个文本框,显示英雄的名称

        [alert textFieldAtIndex:0].text = hero.name;

         [alert show];

    19// 表格的局部刷新

        NSIndexPath *path = [NSIndexPath indexPathForRow:row inSection:0];

        [self.tableView reloadRowsAtIndexPaths:@[path] withRowAnimation:UITableViewRowAnimationBottom];

    20、跳转控制器的三种方法:

    1->push

    2->modal

    3->改变窗口的根视图控制器

    [UIApplication sharedApplication].keyWindow.rootViewController = mainVc;


  • 相关阅读:
    csharp: Speech
    软件定义网络基础---OF-Config协议
    软件定义网络基础---OpenFlow协议
    软件定义网络基础---南向接口协议概述
    Win10+Ubuntu18.04安装双系统
    软件定义网络基础---OpenFlow流表
    软件定义网络基础---OpenFlow概述
    软件定义网络基础---SDN数据平面
    软件定义网络基础---SDN的核心思想
    软件定义网络基础---SDN的主流构架
  • 原文地址:https://www.cnblogs.com/bluceZ/p/4629646.html
Copyright © 2011-2022 走看看