2015-11-05 11 views
15

आईओएस 8 के बाद से, एक रूप में UITextFields बहुत अजीब व्यवहार करते हैं। यदि मैं किसी अन्य टेक्स्ट फ़ील्ड पर क्लिक करता हूं या कीबोर्ड पर टैब दबाता हूं, तो दर्ज टेक्स्ट ऊपर की ओर एनिमेट करता है और फिर तेज़ी से फिर से दिखाई देता है। यह देखने के बाद हर बार होता है, और हर अब और उसके बाद।इस्तीफाफिल्ड इस्तीफा देने पर एनिमेटिंग क्यों है फर्स्ट रेस्पॉन्डर?

यह इस तरह दिखता है:

#pragma mark - <UITextFieldDelegate> 

- (BOOL)textFieldShouldReturn:(UITextField *)textField 
{ 
    if (textField == self.passwordTextField) { 
     [self loginButtonClicked:nil]; 
    } else if (textField == self.emailTextField) { 
     [self.passwordTextField becomeFirstResponder]; 
    } 

    return YES; 
} 

संपादित करें:

ऐसा लगता है कि इस मुद्दे की तरह अपने कीबोर्ड श्रोताओं के कारण होता है:

मेरे कोड इस तरह दिखता है

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil]; 
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil]; 


- (void)keyboardWillHide:(NSNotification *)sender 
{ 
    self.loginBoxBottomLayoutConstraint.constant = 0; 

    [self.view layoutIfNeeded]; 
} 

- (void)keyboardWillShow:(NSNotification *)sender 
{ 
    CGRect frame = [sender.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue]; 
    CGRect newFrame = [self.view convertRect:frame fromView:[[UIApplication sharedApplication] delegate].window]; 
    self.loginBoxBottomLayoutConstraint.constant = CGRectGetHeight(newFrame); 

    [self.view layoutIfNeeded]; 
} 
+0

इसका मेरे लिए ठीक काम करता है के रूप में किया जाएगा। क्या आप UITextField के कुछ तृतीय पक्ष उप वर्ग का उपयोग कर रहे हैं? –

+0

नहीं, मैं नहीं करता हूं। यह एक सादा 'UITextField' है, और मैं कोई तीसरी पार्टी लाइब्रेरी या जो कुछ भी उपयोग नहीं करता हूं। – gklka

+0

क्या आप सिम्युलेटर पर जांच कर रहे हैं? यदि हाँ आप बाहरी कीबोर्ड का उपयोग कर रहे हैं? –

उत्तर

4

है समस्या हो कि आप

-(void)keyboardWillShow:(NSNotification *)sender 

भले ही में कोड का टुकड़ा को क्रियान्वित कर रहे हैं लगता है चलो कीबोर्ड पहले से सक्रिय है, जो कुछ विरूपण की ओर जाता है।

एक छोटा सा काम के आसपास है, तो कुंजीपटल फ्रेम समायोजित करने से पहले पहले से ही सक्रिय है की जाँच करने के लिए, नीचे

bool isKeyboardActive = false; 

-(void)keyboardWillHide:(NSNotification *)sender 

{ 

    self.boxBottomConstraint.constant = 0; 
    [self.view layoutIfNeeded]; 
    isKeyboardActive = false; 
} 


-(void)keyboardWillShow:(NSNotification *)sender 

{ 

    if (!isKeyboardActive) { 
     CGRect frame = [sender.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue]; 
     CGRect newFrame = [self.view convertRect:frame fromView:[[UIApplication sharedApplication] delegate].window]; 
     self.boxBottomConstraint.constant = CGRectGetHeight(newFrame); 
     [self.view layoutIfNeeded]; 
     isKeyboardActive = true; 
    } 
} 
0

इस

[UIView performWithoutAnimation:^{ 
// Changes we don't want animated here 
}]; 
+0

क्या पसंद है? मुझे समझ में नहीं आता कि मुझे गैर एनिमेटेड ब्लॉक में क्या रखा जाना चाहिए। – gklka

+0

मैं मानता हूं '[self.view लेआउट IfNeeded]; ' – Alistra

4

में अपने कोड लपेटकर प्रयास करें इस

- (void)textFieldDidEndEditing:(UITextField *)textField 
{ 
    [textField layoutIfNeeded]; 
} 

कौन सा मैं आपकी समस्या का समाधान करना चाहिए लगता है की कोशिश करो। UITextField: When beginning input, textfield bounces up, and then bounces down में कुछ इसी तरह की पोस्ट प्राप्त करने वाले

IOS8 Text in TextField Bounces on Focus

मुझे बताएं कि अभी भी हम इस मुद्दे

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

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