一個UISrcollView中多個UITextField的滾動處理
阿新 • • 發佈:2019-02-03
摘譯自: http://stackoverflow.com/questions/484855/how-programatically-move-a-uiscrollview-to-focus-in-a-control-above-keyboard
使用一個例項變數記錄檢視在為鍵盤調整之前的位置,以用於當UITextField返回時恢復到之前的狀態。
//header@interfaceTheViewController:UIViewController<UITextFieldDelegate>{CGPoint svos;}//implementation-(void)textFieldDidBeginEditing :(UITextField*)textField {
svos = scrollView.contentOffset;CGPoint pt;CGRect rc =[textField bounds];
rc =[textField convertRect:rc toView:scrollView];
pt = rc.origin;
pt.x =0;
pt.y -=60;[scrollView setContentOffset:pt animated:YES];}-(BOOL)textFieldShouldReturn:(UITextField*)textField {[scrollView setContentOffset:svos animated:YES];[textField resignFirstResponder];return YES;}