2016-03-02 60 views
0

我在導航欄中有一個自定義的後退按鈕。 當鑰匙出現時,我只需用關閉按鈕替換後退按鈕。 當鍵盤關閉時,我恢復後退按鈕。導航欄按鈕上不需要的動畫

下面是我用設置在左側的導航按鈕的功能:

-(UIBarButtonItem*)configureLeftButtonWithImageName:(NSString*)imageName 
             target:(id)target 
             action:(SEL)action 
{ 
    UIButton *accountButton = [UIButton buttonWithType:UIButtonTypeCustom]; 
    UIImage *buttImage = [UIImage imageNamed:imageName]; 
    [accountButton setImage:buttImage forState:UIControlStateNormal]; 
    float padding = 4; 

    accountButton.imageEdgeInsets = UIEdgeInsetsMake(padding, 0, padding, 2*padding); 
    float buttH = kNavigationButtonHeight + 2*padding; 
    float buttW = buttH; 
    if(buttImage) 
    { 
     buttW = buttH * buttImage.size.width/buttImage.size.height; 
    } 
    accountButton.bounds = CGRectMake(padding, padding, buttW, buttH); 

    [accountButton addTarget:target action:action forControlEvents:UIControlEventTouchUpInside]; 

    UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithCustomView:accountButton]; 
    [self.navigationItem setLeftBarButtonItem:barButtonItem]; 
    return barButtonItem; 
} 

在這裏,我切換:

-(void)kbDidAppear 
{ 
    [self configureLeftButtonWithImageName:@"quit" target:self action:@selector(hideKb:)]; 
} 

-(void)kbDidDisappear 
{ 
    [self configureLeftButtonWithImageName:@"back" target:self action:@selector(navigationBack:)]; 
} 

但是,當返回按鈕被替換的退出按鈕,播放不需要的動畫:

退出按鈕出現在導航欄的左上角,然後位置被動畫到其正常值...

當我從退出按鈕切換回按鈕時,問題不出現!

回答

0

我剛剛發現了一個解決辦法,我是從按鈕開關在 UIKeyboardWillShowNotification回調退出按鈕,如果我這樣做在UIKeyboardDidShowNotification回調,沒有更多的怪異動畫