मैं "अगर मैं नहीं करने के लिए एनिमेटेड सेट, सब कुछ काम करता है के रूप में उम्मीद" भाग सहित एक ऐसी ही समस्या का सामना करना पड़ा।
यह पता चला कि IOS 6 पर UITextView ऑटो स्क्रॉल अपने निकटतम माता पिता UIScrollView कर्सर दृश्यमान बनाने के लिए जब वह पहली बार प्रत्युत्तर हो जाता है। आईओएस 7 पर ऐसा कोई व्यवहार नहीं है। UIScrollView एक ही समय में scrollRectToVisible स्क्रॉल करने के लिए दो कॉलों से उलझन में प्रतीत होता है।
आईओएस 6 पर स्क्रॉल करने के लिए मेरी स्पष्ट कॉल स्क्रूटेक्विबल को अधिकांश समय अनदेखा किया जाता है। यह केवल यूआईटीएक्स्टव्यू दृश्य (ऑटो स्क्रॉल) की पहली पंक्ति बनाने के लिए स्क्रॉल करेगा और आईओएस 7 पर पूरी चीज नहीं करेगा।
इसका परीक्षण करने के लिए, एक्सकोड 5 में एक नया एकल दृश्य ऐप बनाएं, इसे सेट करें 6.0 पर तैनाती लक्ष्य और ViewController.m के लिए नीचे दिए गए कोड का उपयोग करें। इसे आईओएस 6.1 सिम्युलेटर में चलाएं, UITextView को छिपाने के लिए स्क्रॉल करें और स्क्रीन पर कहीं भी टैप करें। आपको इसे कुछ बार पुनः प्रयास करना पड़ सकता है, लेकिन ज्यादातर मामलों में यह केवल पहली पंक्ति दिखाई देगा।यदि आप वर्कअर्ड परिभाषित करते हैं तो UITextView को अपने स्वयं के UIScrollView में एम्बेड किया जाता है और स्क्रॉल करने के लिए कॉल की आवश्यकता होती है।
#import "ViewController.h"
//#define WORKAROUND
@interface ViewController()
@property (nonatomic, strong) UIScrollView *scrollView;
@property (nonatomic, strong) UITextView *textView;
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[self.view addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(viewTap)]];
self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 240)];
self.scrollView.contentSize = CGSizeMake(320, 400);
self.scrollView.backgroundColor = [UIColor lightGrayColor];
[self.view addSubview:self.scrollView];
#ifdef WORKAROUND
UIScrollView* dummyScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(20, 280, 280, 100)];
self.textView = [[UITextView alloc] initWithFrame:dummyScrollView.bounds];
[dummyScrollView addSubview:self.textView];
[self.scrollView addSubview:dummyScrollView];
#else
self.textView = [[UITextView alloc] initWithFrame:CGRectMake(20, 280, 280, 100)];
[self.scrollView addSubview:self.textView];
#endif
self.textView.backgroundColor = [UIColor grayColor];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWasShown:) name:UIKeyboardDidShowNotification object:nil];
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)viewTap
{
if (self.textView.isFirstResponder) {
[self.textView resignFirstResponder];
}
else {
[self.textView becomeFirstResponder];
}
}
- (void)keyboardWasShown:(NSNotification*)aNotification
{
#ifdef WORKAROUND
[self.scrollView scrollRectToVisible:CGRectInset(self.textView.superview.frame, 0, -10) animated:YES];
#else
[self.scrollView scrollRectToVisible:CGRectInset(self.textView.frame, 0, -10) animated:YES];
#endif
}
@end
स्रोत
2013-12-21 13:39:02
इस समझ नहीं किया है, लेकिन मैं इसे किया जाना है, तो मैं बस जब तक यह सही जगह पर है एक टाइमर अपने आप शुरू कर दिया और यह स्क्रॉल, setContentOffset का उपयोग कर w/एनिमेटेड: NO। काम करता है लेकिन :( –