zoukankan      html  css  js  c++  java
  • iOS相关的UI最新知识点总结(三)

    1. 设置cell不可选self.tableView.allowsSelection = NO;
    2. UIPickerView的三个数据源方法

    (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView

    (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component

    -(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component

    3.更改图片的拉伸方式的三种方式:

    1)IImage *remeN = [meN resizableImageWithCapInsets:UIEdgeInsetsMake(meN.size.height/2, meN.size.width/2, meN.size.height/2, meN.size.width/2) resizingMode:UIImageResizingModeStretch];

    UIImage *lastImage =  [preImage stretchableImageWithLeftCapWidth:preImage.size.width/2 topCapHeight:preImage.size.width/2];

    3)直接更改图片

    4. awakeFromNib相当于viewDidLoad方法,只有是原型cell和从xib中调用时才会调用此方法,cell每次出现此方法就会出现

    5.setSelected:(BOOL)selected animated:(BOOL)animated,方法在初始化的时候就会多次调用,点击方法就不要写在这里面,点击时也会调用

    6.self.tableView.sectionHeaderHeight = 120;设置组头的高度

    7. @property (nonatomic, assign,getter=isShow) BOOL showFriends;定义属性的方式,方便来调用get方法

    8.bool类型用来区分两种类型,分等级的话使用NSInteger,例如:@property (nonatomic, assign,getter=isVip) NSInteger vip;

    9.一般,属性里面有图片的名称,就会再定义一个UIImage类型的属性相对应,方便使用

    10.返回字符串的组头不满足时,就要定义头部VIEW    .调用方法:

    -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section

    11.组头定义的类为UITableViewHeaderFooterView,使用xib的时候应当注意,以及重用的问题

    -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{

    static NSString *headId = @"head";

    UITableViewHeaderFooterView *headView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:headId];

    if (!headView) {

    //不满足条件,自己定义

    headView = [[UITableViewHeaderFooterView alloc]initWithReuseIdentifier:headId];

    }

    return headView;

    }

    12.init的方法只调用一次,于是设置frame一般是在layoutSubviews里面

    13.如果不适用layoutSubviews,加到contentView上是不会有任何区别的。,但是使用的话,加到上面就是点击contentView上的button就不会刷新布局,layoutSubviews刷新的是headview上的子控件,contentView拦截了刷新,所以上面如果有点击事件时,就应当添加到self上面,而不是self. contentView

    14.点击按钮的旋转,通过点击改变bool类型的属性(取反),判断属性yes or no更改旋转和复位即可

    if (self.friendGroup.isShow) {

    self.btn.imageView.transform = CGAffineTransformMakeRotation(M_PI_2);

    }else{

    self.btn.imageView.transform = CGAffineTransformIdentity;

    }

    }

    15.如果点击按钮是有顺序的,并且调用的方法也是有顺序的可以使用button的tag值进行操作,例如,点击tableView的组头,设置对应组的显示和隐藏(只需要数据原方法设置返回的行数return friendGroup1.showFriends? friendGroup1.friends.count:0;),利用btn.tag = section;,简化button的相应事件的区分

    16.注意取反功能的实现(简化操作)

    17.设置图片的中心位置,以及不被削边

    btn.imageView.contentMode = UIViewContentModeCenter;

    btn.imageView.clipsToBounds = NO;

    18.如果使用代码直接创建约束,先取消autorealesing

    View.translatesAutoresizingMaskIntoConstraints = NO;,添加约束记得先添加到父控件里面

    19. 约束的添加

    NSLayoutConstraint *blueLeft =[NSLayoutConstraint constraintWithItem:blueView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeLeft multiplier:1 constant:20];

    [self.view addConstraint:blueLeft];

    20.使用约束设置动画,先设置更改好的约束,再layout

    self.topConstant.constant += 50;

    [UIView animateWithDuration:2 animations:^{

    [self.view layoutIfNeeded];

     }];

    21.使用masonry约束

    1).导入头文件#import "Masonry.h"

    2).为了方便书写,导入两个宏

    #define MAS_SHORTHAND

    #define MAS_SHORTHAND_GLOBALS

    #define offset(...)                      mas_offset(__VA_ARGS__)

    #define equalTo(...)                     mas_equalTo(__VA_ARGS__)

    3).直接使用约束

    [blueView mas_updateConstraints:^(MASConstraintMaker *make) {

    make.bottom.mas_equalTo(self.view).mas_offset(-100);

     }];

    22.约束可以设置等级,先根据等级高的约束来

    23.使用VFL语言进行约束的设置,但是有的约束不能设置,还是要使用原来的约束进行设置

    1).添加到父控件

    2). .如果使用代码直接创建约束,先取消autorealesing

    View.translatesAutoresizingMaskIntoConstraints = NO;

    3).创建约束数组

    NSArray *H  =[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-20-[blueView]-20-|" options:NSLayoutFormatAlignAllBottom metrics:nil views:@{@"blueView":blueView}];

       

    NSArray *V = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|-20-[blueView(70)]-20-[redView(==blueView)]" options:NSLayoutFormatAlignAllRight metrics:nil views:@{@"blueView":blueView,@"redView":redView}];

    4).将约束数组添加到控件上面

    [self.view addConstraints:H];

    [self.view addConstraints:V];

    24. collectionView的使用,禁止相应点击事件self.collectionView.allowsSelection = NO;

    25.允许多个item同时被点击self.collectionView.allowsMultipleSelection  =YES;

    26. collectionView默认的背景颜色是黑色的,手动设置颜色self.collectionView.backgroundColor= [UIColor whiteColor];

    27. collectionView使用原型cell的时候是不用注册的

    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:ID forIndexPath:indexPath];即使用了原型cell,使用原型cell是最最简单的哦

    28.使用UICollectionReusableView设置不同的头部不然头部的属性除了宽高不会显示,可以通过ID来区分值是头和尾

    一般的使用步骤

    1).static NSString * ID;

    2). ID = [kind isEqualToString:UICollectionElementKindSectionHeader]? @"header":@"footer";

    3).

    if ([kind isEqualToString:UICollectionElementKindSectionHeader]) {

    resView =[collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:ID forIndexPath:indexPath];

    UILabel *lab = [resView viewWithTag:20];

    lab.text = carGroup.title;

        }else{

    resView =[collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:ID forIndexPath:indexPath];

        }

     4).

    29.如果使用代码创建UICollectionView记得创建UICollectionViewFlowLayout,然后通过UICollectionView *collectIionView = [[UICollectionView alloc]initWithFrame:CGRectZero collectionViewLayout:flowLyout];创建,frame没有先设置为CGRectZero

    30.通过UICollectionViewFlowLayout的属性可以设置一些常见的属性

    flowLyout.itemSize = CGSizeMake(100, 100);

    flowLyout.minimumInteritemSpacing = 20;

    flowLyout.minimumLineSpacing = 30;

    flowLyout.sectionInset  = UIEdgeInsetsMake(20, 20, 20, 20);

    31.如果是自定义的cell(纯代码创建的),记得注册类

    //[类名 +class]

    [collectIionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:ID];

    32.如果是使用的xib创建的,记得注册xib

    UINib *nib  = [UINib nibWithNibName:@"myCollectView" bundle:[NSBundle mainBundle]];

    [self.collectView registerNib:nib forCellWithReuseIdentifier:ID];

    33. collectView的一些设置

    self.collectionView.showsHorizontalScrollIndicator  =NO;

    self.collectionView.showsVerticalScrollIndicator = NO;

    self.layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;

    由于继承自scrollView

    self.collectionView.pagingEnabled = YES;

    self.collectionView.bounces = NO;

    34.使用collectionViewCell’(原型)里面的ImageView(并非原来的属性而是脱去的控件)通过tag值获取出来UIImageView *imgView = [cell viewWithTag:10]; UILabel *lab = [cell viewWithTag:40];这样不用进行脱线也能获取到控件

    34.设置无限轮播,伪装的无限轮播

    -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{

        return 10000;

    }

    imgView.image = self.imageArray[(indexPath.item)%self.imageArray.count];

    35. 要用UICollectionView仿一个普通样式的UITableView

      关键: item没有办法加约束,而通过layout的图形界面中又没有办法设置不同屏幕下的尺寸,所以需要通过代码设置

      注意: UICollectionView的头尾,如果没有实现代理方法,只有宽高起作用,内部的属性 内容都不显示

    36.

    显示为UITableView带有头标签的普通样式

    self.flowLayout.sectionHeadersPinToVisibleBounds = YES;

    37.无限轮播

      1. 滚动的方向

      2. 最小间距

      3. 分页功能

      4. 取消滚动条

      5. 取消弹簧效果

      6. 无限循环

    38.UICollectionView自定义layout实现

       最好是继承自 UICollectionViewFlowLayout而不要继承子UICollectionViewLayout

       itemSize等一些设置,都在flowLayot中,如果是继承子UICollectionViewLayout那所有的关于如何设置

    39. 如何判断contentOffset是正负去看相对于内部控件来说,父控件移动的方向

    40. 视网膜屏:又叫Retain屏幕,就是高清视网膜屏幕,分辨率宽高是标准屏幕分辨率的2倍

    41. 图片的命名规则:

    1x图片: 直接使用文件名 btn_left.png

    2x图片: 在文件名后加上@2x标识 btn_left@2x.png

    3x图片: 在文件后加上@3x标识 btn_left@3x.png

    42.

    iPhone3GS的手机,是非视网膜屏幕,它的点 和 分辨率 是相同的,也就是两者相除 得 1

    在iphone4/4S/5/5C//5S/6,它们都是视网膜屏幕,分辨率正好是点的两倍,相除得2

    而在iPhone6 Plus,虽然也是视网膜屏幕,但是分辨率是点的三倍,也就是相除得3

    43.

    M:Model 模型数据

    V:View 可视化的视图界面

    C:Controller 控制器,管理器

    44.方法的重载,方法名相同,参数类型个数不同

  • 相关阅读:
    七月算法--12月机器学习在线班-第七次课笔记—最大熵
    七月算法--12月机器学习在线班-第八次课笔记—推荐系统
    七月算法--12月机器学习在线班-第九次课笔记—推荐系统
    七月算法--12月机器学习在线班-第十次课笔记—人工神经网络
    常用测试用例总结
    word 保存错误
    Mysql(免安装版)安装、配置与卸载
    谈谈日志
    idea maven 仓库配置
    如何建立你自己的开发知识体系---转载
  • 原文地址:https://www.cnblogs.com/chaoyueME/p/5564393.html
Copyright © 2011-2022 走看看