如何让view随着键盘移动

简介: 常见的一个功能,让控件随着Keyboard上下移动而移动,实现方法很多,下面是一个比较方便的方法:#pragma mark - 键盘改动的时候其他view随着变化-(void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; [[NSNotificationCenter de

常见的一个功能,让控件随着Keyboard上下移动而移动,实现方法很多,下面是一个比较方便的方法:

#pragma mark - 键盘改动的时候其他view随着变化
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardShow:) name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardHide:) name:UIKeyboardWillHideNotification object:nil];

}

-(void)keyboardShow:(NSNotification *)note
{
    NSLog(@"show");
    CGRect keyBoardRect=[note.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
    CGFloat deltaY=keyBoardRect.size.height;
    [UIView animateWithDuration:[note.userInfo[UIKeyboardAnimationDurationUserInfoKey] floatValue] animations:^{
  self.yourview=CGAffineTransformMakeTranslation(0, -deltaY);
    }];
}
-(void)keyboardHide:(NSNotification *)note
{
    NSLog(@"hide");
    [UIView animateWithDuration:[note.userInfo[UIKeyboardAnimationDurationUserInfoKey] floatValue] animations:^{
       self.yourview = CGAffineTransformIdentity;
    }];
}//点击返回键
相关文章
|
Java Android开发
如何设置底部控件view随着软键盘的弹出而上移_Android基础篇(Java)
如何设置底部控件view随着软键盘的弹出而上移_Android基础篇(Java)
951 0
如何设置底部控件view随着软键盘的弹出而上移_Android基础篇(Java)
|
XML 数据安全/隐私保护 Android开发
android如何让布局一直在键盘上方显示
在实际项目中,肯定会有输入数据的情况,这样就会用到键盘。
|
Android开发
EditText(防止进入页面就获取焦点弹出键盘)
(创建于2016/11/7) 只需要在该页面所在的activity的manifest中添加 android:windowSoftInputMode="adjustPan|stateHidden" stateHidden是为了隐藏键盘,adjustPa...
1035 0
|
Android开发
Android去除按下HOME按键后上方的搜索框
找到布局文件:packages\apps\Launcher3\res\values\dimens.xml +74将48dp改为0dp  48dp找到相关触发代码:packages\apps\Launcher3\src\com\android\launcher3\allapps\DefaultAppSearchController.
672 0
|
Android开发 数据格式 XML
android使用shape做selector按钮按下和弹起的动画
平时效果:   按下效果: selector代码: ...
1161 0