• iOS相关的UI最新知识点总结(一)


    这是我学习UI,感觉哪里难点,易错点,以及一些不容易记住的点,来和大家分享,也希望大家可以为我指正

    1. [self.num1 resignFirstResponder] 注册成为第一响应者
    2. int sum = s1.intValue+[s2 intValue]将对象转化成为int类型
    3. [self.view endEditing:YES]当前的视图辞去第一响应者
    4. UITextField有时不会弹出键盘 commond+k
    5. NSLog(@”%@”,NSStringFromCGRect(range));
    6. Frame不能直接更改值:采用以下方式更改
    7. CGRect frame=self.Button.frame;
    8. frame.origin.x-=10;

    9.self.Button.frame=frame;

    10.在更改frame,有的时候设置use Auto Layout可能导致按钮不起作用

    11.在设置不同的控件,界面,controller时可以通过tag值进行区分

    12.首位式动画

    [UIView beginAnimations:nil context:nil];

    [UIView setAnimationDuration:2];

    [UIView setAnimationRepeatCount:2];

     设置动画变化的内容

    [UIView commitAnimations];

    13.block动画的使用

    [UIView animateWithDuration:1 animations:^{

     在这里写需要被动画的代码

    }];,不管是block还是手尾式动画,都是UIView的类方法

    14.frame和bounds可以代表一个控件的大小.如果修改frame,控件是保持左上角不变,如果修改的是bounds,控件保持中心点不变.

    15. 移动一行代码快捷键: cmd + option + [

    16.更改图片的大小位置,使用transform,自带动画效果

    self.pic.transform = CGAffineTransformTranslate(self.pic.transform, 0, -10);//更改偏移量

    self.pic.transform = CGAffineTransformRotate(self.pic.transform,M_PI_4);//更改角度

    self.pic.transform = CGAffineTransformScale(self.pic.transform, 1.2, 1.2);//更改大小

    17. if (self.myimgView.isAnimating) {

            return;

        }//判断如果动画正在播放就直接返回,而不执行按钮的点击事件

    _myimgView.animationImages = arr;,设置UIImageView的动画数组

    _myimgView.animationDuration = 0.05*count;//动画播放时间

    _myimgView.animationRepeatCount = 2;//动画重复次数

     

     [_myimgView startAnimating];//开始动画

    动画结束的时候记得清空动画数组

    [self performSelector:@selector(clear) withObject:nil afterDelay:(0.05*2*count)];

    -(void)clear{

        self.myimgView.animationImages = nil;//在动画执行之后清空

    }

    18. UIImage *image = [UIImage imageNamed:str];相比UIImage *img = [UIImage imageWithContentsOfFile:path];浪费内存

    [NSBundle mainBundle]根据图片的名称获取图片在手机上的存储路径

    19. self.preBtn.enabled = (self.index != 0);直接将判断结果当做使能条件

    20.九宫格的关键

    //行号为

     int row = i/colNum;

    //列号

     int col = i%colNum;

    CGFloat leftMargin = (self.view.frame.size.width - colNum*width-(colNum-1)*xMargin)/2;

    CGFloat x = lefeMargin + col *(xMargin + width);

    CGFloat y = topMargin + row *(yMargin + heigth);

    21.使用tranform,进行复位

    - (IBAction)rest {

        self.iconImage.transform = CGAffineTransformIdentity;

    }

    22. 对于push和pop,意味着调用UINavigationController的push-、pop-、或者set-方法来修改视图控制器的堆栈

    23. 对于切换tabs,意味着修改UITabBarController的selectedIndex或selectedViewController属性

    24. 对于modal,则意味着调用[UIViewController presentViewController: animated: completion: ]或[UIViewController dismissViewControllerAnimated: completion: ]。

    25. UI控件初始化问题:initWithFrame和initWithCoder、aweakFromNib的执行

    1>.(1)纯代码创建的UI控件不执行aweakFromNib方法和 initWithCoder方法。

    (2)layoutSubciews方法在控件初始化完成后(自身和子控件的实例化结束)调用,方法中能获得到当前控件的frame,以便于给子控件布局。如有子控件,调用两次。

    2.> (1)通过Xib创建UI控件,不会调用init和initwith方法。

         (2)initWithCoder和 aweakFromNib 在这里作用相同,都被系统调用, 当从xib/Storybord文件加载 UIView 的时候,initWithCoder 会执行。

    25. 如果你是直接基于 frame 来布局的,你应该确保在初始化的时候只添加视图,而不去设置它们的frame,把设置子视图 frame 的过程全部放到 layoutSubviews 方法里:不要依赖前一次的计算结果,应该总是根据当前最新值来计算

    26.约束问题:

    如果你是基于 Auto Layout 约束来进行布局,那么可以在 commonInit 调用的时候就把约束添加上去,不要重写 layoutSubviews 方法,因为这种情况下它的默认实现就是根据约束来计算 frame。最重要的一点,把 translatesAutoresizingMaskIntoConstraints 属性设为 NO,以免产生 NSAutoresizingMaskLayoutConstraint 约束,如果你使用 Masonry 框架的话,则不用担心这个问题,mas_makeConstraints 方法会首先设置这个属性为 NO:,不太懂呢

    27. [self.view sizeToFit] 我们一般在不方便手动布局的时候才调用sizeToFit方法,下面我们就具体的看看哪些场合,不适合手动布局:

    1.navigationBar中对navigationItem的设置,(添加两个视图以上的控件到Item)

    2. toolBar中的对UIBarButtonItem的设置(一般我们还要添加弹簧控件)

    上述两种场合就可以用sizeToFit这个方法,来让系统给我们做自动布局。(注意:如果就添加一个控件的话,我们直接设置fram也是可以的)

    3.在tabBar中我们不能手动的添加的子控件,因为tabBar是根据控制器系统默认自动添加的tabBarItem。(猜想系统可能也会自动调用了这个方法)

    4.UILabel中添加文字,然后让调整label的大小来适应文字,我们也调用sizeToFit的方法

     

    28.通过取色计设置颜色

    float red = (float)125 / 255;

    float green = (float)125 / 255;

    float blue = (float)125 / 255;

    UIColor *col = [UIColor colorWithRed:red green:green blue:blue alpha:1];

    29. [UITextField对象 setKeyboardType:UIKeyboardTypeNumberPad];设置键盘

    30. [UITextField对象 setBorderStyle:UITextBorderStyleNone];设置边框类型

    31. }completion:^(BOOL finished) {是block动画完成时候调用的代码

    32. [UITextField对象setPlaceholder:@"请输入…"];

    [UITextField对象setSecureTextEntry:YES]; 密码文本框的文字必须是暗文显示(掩码显示) Secure属性

    [UITextField对象setBorderStyle:UITextBorderStyleRoundedRect];边框是圆的

    33. [self.view endEditing:YES];记得编辑完毕退出键盘,增强用户体验

    34.使用UIView时候记得,如果有按钮的点击事件,记得打开用户交互userInteractionEnabled

    35. [self.answerView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];清楚视图里面的所有子控件

    36.按钮点击的大图效果(即能放大也能缩小)

    - (IBAction)clickMainBtn:(UIButton *)sender {

       

        if (self.cover==nil) {

            [self showBig];

        }else{

            [self showSmall];

        }

    }

    -(void)showBig{

        UIButton *cover = [[UIButton alloc]init];

        cover.frame = self.view.frame;

        cover.backgroundColor = [UIColor blackColor];

        cover.alpha = 0;

        [self.view addSubview:cover];

        CGFloat width = self.view.frame.size.width;

        CGFloat height = width;

        CGFloat x = 0;

        CGFloat y =  (self.view.frame.size.height - width)/2;

        [cover addTarget:self action:@selector(showSmall) forControlEvents:UIControlEventTouchUpInside];

        [UIView animateWithDuration:2 animations:^{

            cover.alpha = 0.5;

            self.mainIconBtn.frame = CGRectMake(x, y, width, height);

            [self.view bringSubviewToFront:self.mainIconBtn];

        }];

    }

     

    -(void)showSmall{

        [UIView animateWithDuration:2 animations:^{

            self.mainIconBtn.frame = self.orign;

            self.cover.alpha = 0;

        } completion:^(BOOL finished) {

            [self.cover removeFromSuperview];

        }];

    }

    37.添加定时器.

    -(void)addTimer{

        self.myTimer = [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(playPic) userInfo:nil repeats:YES];

        //为什么??

        [[NSRunLoop mainRunLoop]addTimer:self.myTimer forMode:NSRunLoopCommonModes]; //必须更改消息循环模式

    }

    -(void)removeTimer{

        [self.myTimer invalidate];

    }

    38.设置pageController的两种字体颜色

    page.pageIndicatorTintColor = [UIColor blueColor];

    page.currentPageIndicatorTintColor = [UIColor redColor];

    39.添加父控件的两种独特的形式

     [self.view insertSubview:page belowSubview:self.sView];

     [self.view insertSubview:page aboveSubview:self.sView];

    40.设置scrollView的偏移量

    [self.sView setContentOffset:CGPointMake(num*self.sView.frame.size.width, 0) animated:YES];

    41.设置pageController的几个关键因素

      1)self.myPage.currentPage(一般在scrollView的代理方法scrollViewDidScroll里面实现)

    2)page.numberOfPages

     

    3)在scrollView里面设置定时器

    -(void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView{

        [self addTimer];

    }//[self.sView setContentOffset:CGPointMake animated:YES];通过设置偏移量开始偏移时调用和

    -(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{

        [self removeTimer];

    }//停止拖拽(手动拖拽)

    42. scrollView 默认是不能滚动的,需要设置一个参数才能滚动contentSize

    43. 设置ScrollView的最大和最小缩放比例。

    self.scrollView.maximumZoomScale = 3;  self.scrollView.minimumZoomScale = 0.4;

    44.通过scrollView设置放大和缩小图片

    self.sview.delegate = self;

    self.sview.minimumZoomScale = 0.3;

    self.sview.maximumZoomScale = 2;

    -(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{

    return scrollView.subviews[0];

    }

    45.通过这只偏移滚动时,最后一张不加动画效果

    if (self.pageControl.currentPage!=4) {

     [self.sview setContentOffset:po animated:YES];

      }else{

      [self.sview setContentOffset:po];

      }

    46.设置当图片滚动一半的时候改变pageConteoller的页码的方式:

    CGFloat s = self.sview.contentOffset.x;

    CGFloat x = self.sview.frame.size.width;

    int num1 = (s+0.5*x)/x;

    self.pageControl.currentPage = num1;

    47.设置状态栏

    }

    -(BOOL)prefersStatusBarHidden{

        return YES;

    }

    48.设置两栏cmd+option+回车,取消两栏option+回车

    49.更改一边的设置option+右边选择左边的

    50.直接创建的tab记得设置数据源self.tableView.dataSource = self;

  • 相关阅读:
    杀死初创科技公司的四大工程陷阱
    杀死初创科技公司的四大工程陷阱
    Linux中su和sudo的用法整理
    Linux中su和sudo的用法整理
    Docket 使用命令
    Docker 部署 portainer
    Linux 双网卡绑定
    docker安装部署,阿里源加速
    nmcli详解
    搭建LAMP环境示例
  • 原文地址:https://www.cnblogs.com/chaoyueME/p/5553303.html
Copyright © 2020-2023  润新知