2013-09-06 25 views

cevap

10

Ama elle

Kullanım tablo görünümlerini setContentOffset veya scrollToRowAtIndexPath

CGPoint scrollPt = CGPointMake(textFieldRect.origin.x, textFieldRect.origin.y); 
    [_tableView setContentOffset:scrollPt animated:YES]; 

    UITableViewCell *cell = (UITableViewCell*) [[textField superview] superview]; 
    [_tableView scrollToRowAtIndexPath:[_tableView indexPathForCell:cell] atScrollPosition:UITableViewScrollPositionTop animated:YES]; 
1

bu deneyin: Aynı şey ama değişim

CGRect frame = [tableViewer frame]; //assuming tableViewer is your tableview 
frame.size.height -= 200; //200 may be a bit off, should be height of keyboard 
[tableViewer setFrame:frame]; 

Ve - = ila + = klavye kaybolduğunda için. Bazı kodlama yapmak istiyorsanız Normalde otomatik normal sorunu çözecektir https://github.com/michaeltyson/TPKeyboardAvoiding kullanmak

+0

Bu benim durumumda işe yarayan tek şey - Teşekkürler! tek soru - klavye açıldığında, "açık animasyon" ile siyah bir arka plan var. –

+0

Masaüstüne nasıl siyah bir arka plan kaldırabilirim/değiştirebilirim? – Lugubrious

+0

Tablo görünümüne değil, sadece klavyenin hareket ettiği "dikdörtgen" e –

4

Ben aynı sorunu yaşadım ve işte benim çözümüm. Umarım yardımcı olur.

- (void) keyboardWillShow: (NSNotification*) aNotification 
{ 
    [UIView animateWithDuration: [self keyboardAnimationDurationForNotification: aNotification] animations:^{ 
     CGSize kbSize = [[[aNotification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size; 
     //change the frame of your talbleiview via kbsize.height 
    } completion:^(BOOL finished) { 
    }]; 
} 

- (void) keyboardDidShow: (NSNotification*) aNotification 
{  
    [UIView animateWithDuration: [self keyboardAnimationDurationForNotification: aNotification] animations:^{ 
     CGSize kbSize = [[[aNotification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size; 
     //change the frame of your talbleiview via kbsize.height 
    } completion:^(BOOL finished) { 
    }]; 
} 

- (void) keyboardWillDisappear: (NSNotification*) aNotification 
{ 
    [UIView animateWithDuration: [self keyboardAnimationDurationForNotification: aNotification] animations:^{ 
     //restore your tableview 
    } completion:^(BOOL finished) { 
    }]; 
} 

- (NSTimeInterval) keyboardAnimationDurationForNotification:(NSNotification*)notification 
{ 
    NSDictionary* info = [notification userInfo]; 
    NSValue* value = [info objectForKey: UIKeyboardAnimationDurationUserInfoKey]; 
    NSTimeInterval duration = 0; 
    [value getValue: &duration]; 

    return duration; 
} 

Olay dinleyicilerini ekleyin ve kaldırın. Bir klavye animasyonu sırasında çoklu olayların alınacağını düşünün.

+0

Neden hem "keyboardWillShow" hem de "keyboardDidShow" öğesine ihtiyacınız var? –

İlgili konular