iOS弹键盘、收键盘

来源:互联网 发布:linux 获取系统时区 编辑:程序博客网 时间:2024/04/26 16:25
 //监听键盘
    [[
NSNotificationCenterdefaultCenter]addObserver:selfselector:@selector(keyBoardShow:)name:UIKeyboardWillShowNotificationobject:nil];
    [[
NSNotificationCenterdefaultCenter]addObserver:selfselector:@selector(keyBoardHide:)name:UIKeyboardWillHideNotificationobject:nil];

#pragma mark弹出键盘
-(void)keyBoardShow:(NSNotification*)notification
{
   //notification.userInfo获得用户的所有信息,userInfo是一个字典,根据key值     为UIKeyboardFrameEndUserInfoKey拿到键盘的frame字符串,将这个字符串转成Rect
   
int y = [[notification.userInfoobjectForKey:UIKeyboardFrameBeginUserInfoKey]CGRectValue].size.height;
   
    [
UIViewanimateWithDuration:0.3animations:^{
       
bgImageView.center= CGPointMake(bgImageView.center.x,bgImageView.center.y-y/2);
    }];
   
   
//logo设置没
   
logoImageView.transform= CGAffineTransformMakeScale(0, 0);

}
#pragma mark收键盘
-(void)keyBoardHide:(NSNotification*)notification
{
    [
UIViewanimateWithDuration:0.3animations:^{
       
bgImageView.center= self.view.center;
       
logoImageView.transform= CGAffineTransformMakeScale(1, 1);
    }];
}
0 0
原创粉丝点击