2011-03-26 79 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對不起。