Iphone Delegation - PullRequest
       4

Iphone Delegation

0 голосов
/ 06 декабря 2010

Привет, я использую следующее для поднятия клавиатуры, у меня есть много контроллеров представления, которые также могут ее использовать, но мои попытки делегировать ее не увенчались успехом.Я определенно не хочу вставлять это в каждый контроллер представления.Буду очень признателен, если появятся какие-либо идеи

- (void)viewWillAppear:(BOOL)animated {

void (^keyBoardWillShow) (NSNotification *)= ^(NSNotification * notif) {
    NSDictionary* info = [notif userInfo];
    NSValue* aValue = [info objectForKey:UIKeyboardFrameEndUserInfoKey];
    CGSize keyboardSize = [aValue CGRectValue].size;  
    float bottomPoint = (ivcTextField.frame.origin.y + ivcTextField.frame.size.height + 10);
    scrollAmount = keyboardSize.height - (self.view.frame.size.height - bottomPoint);

    if (scrollAmount > 0)  {
        moveViewUp =YES;
        [self scrollTheView:YES];
    }
    else
        moveViewUp = NO;
};

[[NSNotificationCenter defaultCenter] addObserverForName:UIKeyboardWillShowNotification object:self.view.window queue:nil 
                                              usingBlock:keyBoardWillShow];

void (^keyBoardWillHide) (NSNotification *)= ^(NSNotification * notif) {
    if (moveViewUp) [self scrollTheView:NO];    
};
[[NSNotificationCenter defaultCenter] addObserverForName:UIKeyboardWillHideNotification object:self.view.window queue:nil 
                                              usingBlock:keyBoardWillHide]; 

[super viewWillAppear:animated];  

} - (пусто)

1 Ответ

0 голосов
/ 06 декабря 2010

Эти методы будут выполняться для класса UIViewController, поэтому я думаю, что вы можете обернуть эти методы в категорию UIViewController.

@interface UIViewController (Ext_Keyboard)

- (void)registerObserverForKeyboardDidShow;
- (void)unregisterObserverForKeyboardDidShow;

- (void)registerObserverForKeyboardDidHide;
- (void)unregisterObserverForKeyboardDidHide;

@end 
...