开发者

UIScrollView autoscrolls after I set contentOffset

开发者 https://www.devze.com 2023-03-31 07:19 出处:网络
I am trying to navigate through UITextFields while the keyboard is up.I have an xib setup with a UIScrollView with textfields inside.I have the contentOffset.y changing when a UITextField is set to th

I am trying to navigate through UITextFields while the keyboard is up. I have an xib setup with a UIScrollView with textfields inside. I have the contentOffset.y changing when a UITextField is set to the first responder. The first two textfields react normally, but after that the scrollview will shoot past the selected text field, and will get progressively worse the farther down the list I get. I have s开发者_运维知识库etup NSLog statements, and breakpoints which have shown me that when I first select the textfield, the correct y value is used, but then the scrollview's scrollViewDidScroll method is called directly after several times, running past the textfield.

-(void)textFieldDidBeginEditing:(UITextField *)textField{  
  textField.inputAccessoryView = accessoryBar;
  int offset = 30;
  [scrollView setContentOffset:CGPointMake(0, textField.frame.origin.y -offset) ];
}

-(void)textFieldDidEndEditing:(UITextField *)textField{  
  [scrollView setContentOffset:CGPointMake(0, 0)];
}  

-(BOOL) textFieldShouldReturn:(UITextField*) textField {
  [textField resignFirstResponder]; 
  return YES;
}

I am running iOS 4.3 on xcode 4.1 lion


Maybe your accessoryBar is messing things up? The inputAccessoryView property is normally read only, so I assume you have subclassed UITextField. Try your code without the accessoryBar.

0

精彩评论

暂无评论...
验证码 换一张
取 消