码迷,mamicode.com
首页 > 移动开发 > 详细

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

时间:2015-10-15 15:41:41      阅读:279      评论:0      收藏:0      [点我收藏+]

标签:

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);
        }
    }];
}

 

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

标签:

原文地址:http://www.cnblogs.com/wujy/p/4871197.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!