Aug 29, 2015 - Objc中self.xx和_xx的区别

Comments

在公司第一次commit代码时,被同事吐槽了n次,所有的init的方法全部写在了viewDidLoad里面,而self.XX和_XX之间又相互乱用,导致重构代码时费了不少时间。在此对ObjC中self.XX和_XX的区别进行记录一下:
前者调用该类的setter或getter方法,后者直接获取自己的实例变量。在类的m文件里可以直接用实例变量名来访问自身的实例变量,但是setter和getter方法不会被调用。外部想用该类的实例变量需要用getter和setter方法。

Aug 29, 2015 - 点击空白处关闭键盘

Comments

给 view 注册一个点击手势,在 view 点击时放弃“第一响应者”

#pragma mark 点击空白处关闭键盘
- (void)viewDidLoad {
    [super viewDidLoad];
    //点击空白处关闭键盘
    UITapGestureRecognizer* tapGr = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(viewTapped:)];
    tapGr.cancelsTouchesInView = NO;
    [self.view addGestureRecognizer:tapGr];
}

-(void)viewTapped:(UITapGestureRecognizer *)tapGr{
    [_noteContent resignFirstResponder];
}

Aug 29, 2015 - Imageview的contentmode属性

Comments

UIViewContentModeScaleToFill 缩放以填充

UIViewContentModeScaleAspectFit 缩放以显示全部,比例不变

UIViewContentModeScaleAspectFill 缩放显示,填满,比例不变