Scrollview在[textview resignFirstResponder]之后停止滚动

时间:2011-03-26 00:58:19

标签: iphone ios textview scrollview

解释问题并不容易,但我会尝试: 我有一个女巫滚动视图和很多textview和textfield。

当有人想要编辑一个字段(或textview)时,我想向上和向下滚动,所以我有:

- (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;
}
像苹果医生说的那样。 Offcourse activefield是通过

分配的UIView *
-(void)textFieldDidBeginEditing:(UITextField *)textField {
NSLog(@"textFieldDidBeginEditing");
activefield=textField;

}

- (void)textViewDidBeginEditing:(UITextView *)textView{
NSLog(@"textViewDidBeginEditing");
activefield=textView;
}

确定一切正常,但

时除外
- (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;
}

当我上下移动手指时,后辞职滚动视图(_scrollview)停止移动。

建议。

1 个答案:

答案 0 :(得分:0)

好的,我添加了

[textView resignFirstResponder]之后

[o_scrollview成为第一反应者];

对不起。