不讓鍵盤擋住UITextField

來源:互聯網
上載者:User
第一個問題:當游標定位到UITextField進行輸入時,鍵盤會蓋住UITextField,無法看到輸入的內容, 如何當UITextField得到焦點時,動態移動UITextField控制項,而不讓鍵盤擋住UITextField控制項,就象iphone版本的QQ登入介面一樣,當輸入使用者名稱或密碼時,整個View都會動態移動到合適位置,以免被鍵盤擋住,二示。-(UITextView *)textView{    NSLog(@"   begin editing ");    [postScrollView setContentOffset:CGPointMake(0, 150) animated:YES];    return YES;}//寫完之後  在某一個事件方法中(如:發送的方法)取消焦點:[postTextView resignFirstResponder];  接下來會自動運行一下委託:- (void)textViewDidEndEditing:(UITextView *)textView{    NSLog(@"   did end editing ");    [postScrollView setContentOffset:CGPointMake(0.0, 0.0) animated:YES];} 第二個問題:如何在空白處點擊自動隱藏鍵盤(在UITextField控制項之外點擊),二示。- (BOOL)textViewShouldBeginEditing:UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideKeyBoard:)];    tapGestureRecognizer.numberOfTapsRequired = 1;    [myScrollView addGestureRecognizer: tapGestureRecognizer];   //只需要點擊非文字輸入地區就會響應hideKeyBoard- (void)hideKeyBoard:(id)sender{  [myTextView  resignFirstResponder];//or [myTextField resignFirstResponder];}用self.view.center = CGPointMake(x,y)來移動view就可以解決鍵盤檔住的問題, 其中x代表x軸的座標,y代表y軸的座標整個畫面往上移

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.