六月丁香五月婷婷,丁香五月婷婷网,欧美激情网站,日本护士xxxx,禁止18岁天天操夜夜操,18岁禁止1000免费,国产福利无码一区色费

學(xué)習(xí)啦 > 學(xué)習(xí)電腦 > 電腦硬件知識(shí) > 鍵盤鼠標(biāo) > 怎么使iOS中的鍵盤適應(yīng)高度變化

怎么使iOS中的鍵盤適應(yīng)高度變化

時(shí)間: 沈迪豪908 分享

怎么使iOS中的鍵盤適應(yīng)高度變化

  在ios開(kāi)發(fā)時(shí)我們會(huì)遇到鍵盤高度無(wú)法適應(yīng)的問(wèn)題,這時(shí)候該怎么解決呢?下面由學(xué)習(xí)啦小編教大家怎么解決iOS中的鍵盤高度變化的問(wèn)題。
完美解決iOS中的鍵盤適應(yīng)高度變化的方法

  #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;

  }];

  }

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

猜你喜歡:

1.學(xué)習(xí)啦在線學(xué)習(xí)網(wǎng)

2.怎樣把電腦上的照片導(dǎo)入iphone

3.iphone照片怎么導(dǎo)入電腦

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

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

6.iPhone5s怎么刷機(jī)

1940038