2014-11-14 48 views
0

我試圖在編輯模式之間切換tableView時,在backBarButtonItem和取消按鈕之間獲得平滑的動畫。在backBarButtonItem和UIBarButtonItem之間進行動畫處理

- (void)setEditing:(BOOL)editing animated:(BOOL)animated 
{ 
    [super setEditing:editing animated:animated]; 
    UIBarButtonItem *leftButton = editing ? [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:nil] : self.navigationItem.backBarButtonItem; 
    [self.navigationItem setLeftBarButtonItem:leftButton animated:YES]; 
} 

這正確地更改了leftBarButtonItem,但該更改是即時而非預期的動畫過渡。我也用[self.navigationController.navigationItem setHidesBackButton:YES animated:YES];嘗試過各種各樣的東西,但是所有的動畫都有些不可思議。

任何人都有這個想法,上面的代碼與兩個UIBarButtonItems一起工作,但與backBarButtonItem斷開。

我很感激任何幫助,謝謝。

編輯

這是我目前最好的解決辦法,動畫仍雖然略有似乎離我。

- (void)setEditing:(BOOL)editing animated:(BOOL)animated 
{ 
    [super setEditing:editing animated:animated]; 

    if (editing) { 
     [self.navigationItem setHidesBackButton:YES animated:NO]; 
     [self.navigationItem setLeftBarButtonItem:[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:nil] animated:YES]; 
    } else { 
     self.navigationItem.leftBarButtonItem = nil; 
     [self.navigationItem setHidesBackButton:NO animated:YES]; 
    } 
} 

回答

0

把改變一個UIView動畫塊:

[UIView animateWithDuration:0.5 animations:^(void) { 
     self.navigationItem.leftBarButtonItem = leftButton; 
    }]; 

您可以再與動畫製作的速度鼓搗。

+0

感謝您的建議,它提供了一個合適的從barButton到backButton的淡入淡出動畫,但是在另一個方向上是一個奇怪的縮放動畫。 – steharro 2014-11-14 23:52:40

相關問題