Scrollview stop scrolling after [textview resignFirstResponder]
it's not really easy to explain the problem but i will try: I've a view witch scrollview and inside a lot of textview and textfield.
I want to scroll up and down when someone开发者_JAVA技巧 didbegin editing one field(or textview), so i have:
- (void)keyboardDidShow:(NSNotification*)aNotification{
NSDictionary* info = [aNotification userInfo];
CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
UIEdgeInsets contentInsets = UIEdgeInsetsMake(0.0, 0.0, kbSize.height, 0.0);
o_scroolView.contentInset = contentInsets;
o_scroolView.scrollIndicatorInsets = contentInsets;
// If active text field is hidden by keyboard, scroll it so it's visible
// Your application might not need or want this behavior.
CGRect aRect = self.view.frame;
aRect.size.height -= kbSize.height;
if (!CGRectContainsPoint(aRect, activefield.frame.origin) ) {
CGPoint scrollPoint = CGPointMake(0.0, activefield.frame.origin.y-kbSize.height);
[o_scroolView setContentOffset:scrollPoint animated:YES];
}
}
- (void)keyboardDidHide:(NSNotification*)aNotification
{
UIEdgeInsets contentInsets = UIEdgeInsetsZero;
o_scroolView.contentInset = contentInsets;
o_scroolView.scrollIndicatorInsets = contentInsets;
activefield=NULL;
}
like apple doc say. Offcourse activefield is a UIView* assigned via
-(void)textFieldDidBeginEditing:(UITextField *)textField {
NSLog(@"textFieldDidBeginEditing");
activefield=textField;
}
- (void)textViewDidBeginEditing:(UITextView *)textView{
NSLog(@"textViewDidBeginEditing");
activefield=textView;
}
ok everything work well except that when
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range
replacementText:(NSString *)text
{
// Any new character added is passed in as the "text" parameter
if ([text isEqualToString:@"\n"]) {
// Be sure to test for equality using the "isEqualToString" message
// [self EnablePrice:TRUE];
[textView resignFirstResponder];
// Return FALSE so that the final '\n' character doesn't get added
return FALSE;
}
// For any other character return TRUE so that the text gets added to the view
return TRUE;
}
The after resign scrollview (_scrollview) stop moving when i shift my finger up and down.
Thx in advice.
Ok i added
[o_scrollview becomefirstresponder] after [textView resignFirstResponder];
Nvm sorry.
精彩评论