2012-05-05 15 views
6

मुझे एक बड़ी UITextView मिली है, लगभग पूर्ण स्क्रीन। अगर मैं इसे टैप करता हूं, तो कीबोर्ड पॉप अप हो जाता है और मैं टेक्स्ट को संपादित कर सकता हूं। हालांकि, जितना अधिक मैं टाइप करता हूं, आखिर में टेक्स्ट कीबोर्ड के पीछे दृश्य को चलाता है। अब मैं नहीं देख सकता कि मैं क्या टाइप कर रहा हूं।UITextView, संपादन करते समय स्क्रॉल करें?

आप इससे कैसे निपटते हैं? क्या आपको कर्सर की स्थिति को ट्रैक करना है और मैन्युअल रूप से दृश्य को स्क्रॉल करना है?

उत्तर

5

कुंजीपटल शो/छुपाएं के रूप में अपना UITextView आकार दें। तो कीबोर्ड आपके टेक्स्टव्यू पर नहीं होगा। नमूना कोड यहां दिए गए हैं।

- (void)viewDidLoad 
{ 
    [[NSNotificationCenter defaultCenter] addObserver:self 
              selector:@selector(keyboardWillShow:) 
               name:UIKeyboardWillShowNotification 
               object:nil]; 
    [[NSNotificationCenter defaultCenter] addObserver:self 
              selector:@selector(keyboardWillHide:) 
               name:UIKeyboardWillHideNotification 
               object:nil]; 
} 

- (void)keyboardWillShow:(NSNotification *)notification 
{ 
    [UIView beginAnimations:nil context:nil]; 
    CGRect endRect = [[notification.userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue]; 
    CGRect newRect = YOUT_TEXT_VIEW.frame; 
    //Down size your text view 
    newRect.size.height -= endRect.size.height; 
    YOUT_TEXT_VIEW.frame = newRect; 
    [UIView commitAnimations]; 
} 

- (void)keyboardWillHide:(NSNotification *)notification 
{ 
    ... // Resize your textview when keyboard is going to hide 
} 
+0

थानक्स प्रिय थैंट थे। – jamil

7

आप स्क्रॉल नीचे TextView के लिए निम्नलिखित कोड का उपयोग करने के लिए पाठ सीमा के अनुसार (या कहना टाइपिंग के अनुसार) मैं तुम्हें करने के लिए है लगता है की जरूरत है

NSRange range = NSMakeRange(textView.text.length - 1, 1); 
[textView scrollRangeToVisible:range]; 

आशा, यह आप में मदद मिलेगी ...

+0

प्रतिक्रिया के लिए थैंक्स .. लेकिन मुझे वह लिंक मिला जो मैं करना चाहता हूं .. अविश्वसनीय लिंक जो ठीक काम करता है। – jamil

+3

https://developer.apple.com/library/ios/#samplecode/KeyboardAccessory/Listings/Classes_ViewController_m.html – jamil

+3

@ user1328096 वंशावली के लिए क्या आप अपने प्रश्न का समाधान उचित उत्तर के रूप में लिख सकते हैं? (और कुछ जवाब स्वीकार करना न भूलें!) –

2

TPKeyboardAvoiding एक बेहतरीन टूल है जो आपके लिए कीबोर्ड से बचने के लिए सभी स्क्रॉलिंग को संभालता है।/बहुत/आसान और अत्यधिक अनुशंसित। देखें: https://github.com/michaeltyson/TPKeyboardAvoiding

+0

वाह, क्या एक मणि TPKeyboardAvoiding है! – thomers

संबंधित मुद्दे