• iOS开发基础知识--碎片24


     

     iOS开发基础知识--碎片24

    1:兼容字体大小6plue跟它以下的区别

    #define FONT_COMPATIBLE_SCREEN_OFFSET(_fontSize_)  [UIFont systemFontOfSize:(_fontSize_ *([UIScreen mainScreen].scale) / 2)]

    在iPhone4~6中,缩放因子scale=2;在iPhone6+中,缩放因子scale=3

    运用时:

    myLabel.font=FONT_COMPATIBLE_SCREEN_OFFSET(15);

     扩展:画一像素的宏

    #define SINGLE_LINE_WIDTH           (1 / [UIScreen mainScreen].scale)
    #define SINGLE_LINE_ADJUST_OFFSET   ((1 / [UIScreen mainScreen].scale) / 2)

    运用时:

    CGFloat xPos = 5;
        UIView *view = [[UIView alloc] initWithFrame:CGrect(x - SINGLE_LINE_ADJUST_OFFSET, 0, SINGLE_LINE_WIDTH, 100)];

    2:APP虚拟器可以运行,在真机调试时报这个问题,因为把产品名称设成中文导致

    App installation failed
    There was an internal API error.
    
    Build Settings中的Packaging的Product Name设置成中文

     3:Xcode证书存放路径

    资源库/MobileDevice/Provisioning Profiles

    4:使用第三方RDVTabBarController底部Tab时

    若要隐藏时把动画关掉,就不会出现一闪的情况

    复制代码
    //隐藏底部菜单
    - (void)viewWillAppear:(BOOL)animated {
        [super viewWillAppear:animated];
        [[self rdv_tabBarController] setTabBarHidden:YES animated:NO];
    }
    
    - (void)viewWillDisappear:(BOOL)animated {
        [super viewWillDisappear:animated];
        [[self rdv_tabBarController] setTabBarHidden:NO animated:NO];
    }
    复制代码

    5:Masonry一些其它内容

    a:make.equalTo 或 make.greaterThanOrEqualTo (至多) 或 make.lessThanOrEqualTo(至少)

    make.left.greaterThanOrEqualTo(label);
    make.left.greaterThanOrEqualTo(label.mas_left);
    
    //width >= 200 && width <= 400
    make.width.greaterThanOrEqualTo(@200);
    make.width.lessThanOrEqualTo(@400)

    b:masequalTo 和 equalTo 区别:masequalTo 比equalTo多了类型转换操作,一般来说,大多数时候两个方法都是 通用的,但是对于数值元素使用mas_equalTo。对于对象或是多个属性的处理,使用equalTo。特别是多个属性时,必须使用equalTo

    c:一些简便赋值

    复制代码
    // make top = superview.top + 5, left = superview.left + 10,
    // bottom = superview.bottom - 15, right = superview.right - 20
    make.edges.equalTo(superview).insets(UIEdgeInsetsMake(5, 10, 15, 20))
    
    // make width and height greater than or equal to titleLabel
    make.size.greaterThanOrEqualTo(titleLabel)
    
    // make width = superview.width + 100, height = superview.height - 50
    make.size.equalTo(superview).sizeOffset(CGSizeMake(100, -50))
    
    // make centerX = superview.centerX - 5, centerY = superview.centerY + 10
    make.center.equalTo(superview).centerOffset(CGPointMake(-5, 10))
    复制代码

    d:and关键字运用

    make.left.right.and.bottom.equalTo(superview); 
    make.top.equalTo(otherView);

    e:优先;优先权(.priority,.priorityHigh,.priorityMedium,.priorityLow)

    复制代码
    `.priority`允许您指定一个确切的优先级
    `.priorityHigh`等价于UILayoutPriorityDefaultHigh
    `.priorityMedium`介于高跟低之间
    `.priorityLow` 等价于UILayoutPriorityDefaultLow
    
    实例:
    
    make.left.greaterThanOrEqualTo(label.mas_left).with.priorityLow();
    make.top.equalTo(label.mas_top).with.priority(600);
    复制代码

    g:使用mas_makeConstraints创建constraint后,你可以使用局部变量或属性来保存以便下次引用它;如果创建多个constraints,你可以采用数组来保存它们

    复制代码
    // 局部或者全局
    @property (nonatomic, strong) MASConstraint *topConstraint;
    
    // 创建约束并赋值
    [view1 mas_makeConstraints:^(MASConstraintMaker *make) {
        self.topConstraint = make.top.equalTo(superview.mas_top).with.offset(padding.top);
        make.left.equalTo(superview.mas_left).with.offset(padding.left);
    }];
    
    // 过后可以直接访问self.topConstraint
    [self.topConstraint uninstall];
    复制代码

    h:mas_updateConstraints更新约束,有时你需要更新constraint(例如,动画和调试)而不是创建固定constraint,可以使用mas_updateConstraints方法

    复制代码
    - (void)updateConstraints {
        [self.growingButton mas_updateConstraints:^(MASConstraintMaker *make) {
            make.center.equalTo(self);
            make.width.equalTo(@(self.buttonSize.width)).priorityLow();
            make.height.equalTo(@(self.buttonSize.height)).priorityLow();
            make.width.lessThanOrEqualTo(self);
            make.height.lessThanOrEqualTo(self);
        }];
        
        //调用父updateConstraints
        [super updateConstraints];
    }
    复制代码

    i:mas_remakeConstraints更新约束,mas_remakeConstraints与mas_updateConstraints比较相似,都是更新constraint。不过,mas_remakeConstraints是删除之前constraint,然后再添加新的constraint(适用于移动动画);而mas_updateConstraints只是更新constraint的值。

    复制代码
    - (void)changeButtonPosition {
        [self.button mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.size.equalTo(self.buttonSize);
            
            if (topLeft) {
           make.top.and.left.offset(10);
            } else {
           make.bottom.and.right.offset(-10);
            }
        }];
    }
  • 相关阅读:
    Maven常用命令:
    正向代理、反向代理、透明代理
    linux命令ps aux|grep xxx详解
    Java中Comparable和Comparator区别小结
    Java Queue之PriorityQueue
    java读写分离的实现
    CSS颜色名称和颜色值
    使用Access-Control-Allow-Origin解决跨域
    Tomcat 下启用 https:// 访问
    使用Jedis操作redis
  • 原文地址:https://www.cnblogs.com/LiLihongqiang/p/5796866.html
Copyright © 2020-2023  润新知