无码天堂亚洲内射精品课堂_日韩AV电影在线观看不卡_日韩精品人妻系列无码AV小草_亚洲极限拳头交异物交极端_中文亚洲无线码49vv

學習啦 > 學習電腦 > 電腦硬件知識 > 鍵盤鼠標 > 怎么使iOS中的鍵盤適應高度變化

怎么使iOS中的鍵盤適應高度變化

時間: 沈迪豪908 分享

怎么使iOS中的鍵盤適應高度變化

  在ios開發(fā)時我們會遇到鍵盤高度無法適應的問題,這時候該怎么解決呢?下面由學習啦小編教大家怎么解決iOS中的鍵盤高度變化的問題。
完美解決iOS中的鍵盤適應高度變化的方法

  #pragma mark - reg & unreg notification

  - (void)regNotification

  {

  [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillChangeFrame:) name:UIKeyboardWillChangeFrameNotification object:nil];

  }

  - (void)unregNotification

  {

  [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillChangeFrameNotification object:nil];

  }

  #pragma mark - notification handler

  - (void)keyboardWillChangeFrame:(NSNotification *)notification

  {

  NSDictionary *info = [notification userInfo];

  CGFloat duration = [[info objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue];

  CGRect beginKeyboardRect = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue];

  CGRect endKeyboardRect = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];

  CGFloat yOffset = endKeyboardRect.origin.y - beginKeyboardRect.origin.y;

  CGRect inputFieldRect = self.inputTextField.frame;

  CGRect moreBtnRect = self.moreInputTypeBtn.frame;

  inputFieldRect.origin.y += yOffset;

  moreBtnRect.origin.y += yOffset;

  [UIView animateWithDuration:duration animations:^{

  self.inputTextField.frame = inputFieldRect;

  self.moreInputTypeBtn.frame = moreBtnRect;

  }];

  }

  通過獲取鍵盤消息的開始狀態(tài)、結(jié)束狀態(tài),以及變化周期,可以計算出具體的Y偏移,從而在相同時間里做相同偏移量。

猜你喜歡:

1.學習啦在線學習網(wǎng)

2.怎樣把電腦上的照片導入iphone

3.iphone照片怎么導入電腦

4.電腦ipad模擬器的安裝方法

5.安卓程序員必備的開發(fā)工具

6.iPhone5s怎么刷機

1940038