标签:style io ar color 使用 sp for on bs
1.首先注册系统通知
//监听键盘通知 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillChangeFrameNotification:) name:UIKeyboardWillChangeFrameNotification object:nil];
2.键盘将要改变时的相应处理
-(void)keyboardWillChangeFrameNotification:(NSNotification *)note{ //取出键盘动画的时间(根据userInfo的key----UIKeyboardAnimationDurationUserInfoKey) CGFloat duration = [note.userInfo[UIKeyboardAnimationDurationUserInfoKey] floatValue]; //取得键盘最后的frame(根据userInfo的key----UIKeyboardFrameEndUserInfoKey = "NSRect: {{0, 227}, {320, 253}}";) CGRect keyboardFrame = [note.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue]; //计算控制器的view需要平移的距离 CGFloat transformY = keyboardFrame.origin.y - self.view.frame.size.height; //执行动画 [UIView animateWithDuration:duration animations:^{ //平移 self.view.transform = CGAffineTransformMakeTranslation(0, transformY); }]; }
3.这样其实还没完(存在内存隐患)还需要重写dealloc方法
-(void)dealloc{
//使用通知中心后必须重写dealloc方法,进行释放(ARC)(非ARC还需要写上[super dealloc];)
//removeObserver和 addObserver相对应.
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
标签:style io ar color 使用 sp for on bs
原文地址:http://my.oschina.net/u/2285956/blog/355935