键盘弹出和收起的通知

来源:互联网 发布:nat模式网络配置 编辑:程序博客网 时间:2024/06/05 05:39
//订阅键盘升起的系统通知     

UILabel* label = [[UILabelalloc]initWithFrame:CGRectMake(0,0,220*2,30)];


- (void)viewDidLoad写下面的代码   

[[NSNotificationCenterdefaultCenter]addObserver:selfselector:@selector(keyboardWillshow)name:UIKeyboardWillShowNotificationobject:nil];         [[NSNotificationCenterdefaultCenter]addObserver:selfselector:@selector(keyboardWillHide)name:UIKeyboardWillHideNotificationobject:nil];     } -(void)keyboardWillshow {  

  [UIViewanimateWithDuration:0.2animations:^{    

   _butn.frame=CGRectMake(20,20,200,20);

//这里写butn要改变的位置   

}completion:^(BOOLfinished) {        

    }];

}

-(void)keyboardWillHide {   

[UIView animateWithDuration:0.2animations:^{   

     _butn.frame = CGRectMake(20,20,200,20);//这里写butn刚开始定义的原位置     } completion:^(BOOLfinished) {   

         }];

}

}

0 0
原创粉丝点击