2011-03-26 77 views
0

解释这个问题并不是很容易,但我会尝试: 我有一个视图witch scrollview,里面有很多textview和textfield。ScrollView在[textview resignFirstResponder]之后停止滚动

我想,当有人didbegin编辑一个字段(或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)后停止,当我我的手指移动上下移动。

Thx in advice。

回答

0

确定我加入

[o_scrollview becomefirstresponder]之后[TextView的resignFirstResponder];

Nvm对不起。