bl双性强迫侵犯h_国产在线观看人成激情视频_蜜芽188_被诱拐的少孩全彩啪啪漫画

iOS中鍵盤彈出會遮擋輸入框如何解決-創新互聯

iOS中鍵盤彈出會遮擋輸入框如何解決?很多新手對此不是很清楚,為了幫助大家解決這個難題,下面小編將為大家詳細講解,有這方面需求的人可以來學習下,希望你能有所收獲。

創新互聯建站堅持“要么做到,要么別承諾”的工作理念,服務領域包括:做網站、網站建設、企業官網、英文網站、手機端網站、網站推廣等服務,滿足客戶于互聯網時代的兩當網站設計、移動媒體設計的需求,幫助企業找到有效的互聯網解決方案。努力成為您成熟可靠的網絡建設合作伙伴!

解決思路:


監聽鍵盤出現和消失的狀態,當鍵盤出現時,當前視圖上移,當輸入完成收起鍵盤時,視圖回到初始狀態。

難點:視圖向上平移的距離

iOS中鍵盤彈出會遮擋輸入框如何解決

原理都差不多,oc版參考代碼:

self.phoneInput = [UITextField new];
  self.phoneInput.placeholder = @"請輸入...";
  [self.view addSubview:self.phoneInput];


///鍵盤彈出 處理遮擋問題
- (void)viewWillAppear:(BOOL)animated
{
  [super viewWillAppear:animated];
  
  [[NSNotificationCenter defaultCenter] addObserver:self
                       selector:@selector(keyboardWillShow:)
                         name:UIKeyboardWillShowNotification
                        object:nil];
  [[NSNotificationCenter defaultCenter] addObserver:self
                       selector:@selector(keyboardWillHide:)
                         name:UIKeyboardWillHideNotification
                        object:nil];
}
- (void)keyboardWillShow:(NSNotification *)notification
{
 //獲取處于焦點中的view
 NSArray *textFields = @[self.phoneInput];
 UIView *focusView = nil;
 for (UITextField *view in textFields) {
  if ([view isFirstResponder]) {
   focusView = view;
   break;
  }
 }
 if (focusView) {
   //獲取鍵盤彈出的時間
   double duration = [notification.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue];
   //獲取鍵盤上端Y坐標
   CGFloat keyboardY = [notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue].origin.y;
   //獲取輸入框下端相對于window的Y坐標
   CGRect rect = [focusView convertRect:focusView.bounds toView:[[[UIApplication sharedApplication] delegate] window]];
   CGPoint tmp = rect.origin;
   CGFloat inputBoxY = tmp.y + focusView.frame.size.height;
   //計算二者差值
   CGFloat ty = keyboardY- inputBoxY;
   NSLog(@"position keyboard: %f, inputbox: %f, ty: %f", keyboardY, inputBoxY, ty);
   //差值小于0,做平移變換
   [UIView animateWithDuration:duration animations:^{
    if (ty < 0) {
     self.view.transform = CGAffineTransformMakeTranslation(0, ty);
    }
   }];
  }
}

- (void)keyboardWillHide:(NSNotification *)notification
{
 //獲取鍵盤彈出的時間
 double duration = [notification.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue];
 //還原
 [UIView animateWithDuration:duration animations:^{
   self.view.transform = CGAffineTransformMakeTranslation(0, 0);
 }];
}
///<UITextFieldDelegate>
///UITextFieldDelegate編輯完成,視圖恢復原狀
-(void)textFieldDidEndEditing:(UITextField *)textField
{
   self.view.frame =CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width,[[UIScreen mainScreen] bounds].size.height);
}

看完上述內容是否對您有幫助呢?如果還想對相關知識有進一步的了解或閱讀更多相關文章,請關注創新互聯行業資訊頻道,感謝您對創新互聯網站建設公司,的支持。

分享題目:iOS中鍵盤彈出會遮擋輸入框如何解決-創新互聯
當前地址:http://vcdvsql.cn/article34/ddjose.html

成都網站建設公司_創新互聯,為您提供App設計外貿網站建設標簽優化電子商務響應式網站網站內鏈

廣告

聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯

商城網站建設