2014-11-14 18 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

相关问题