【问题标题】:Animating Between backBarButtonItem and UIBarButtonItembackBarButtonItem 和 UIBarButtonItem 之间的动画
【发布时间】:2014-11-14 19:29:50
【问题描述】:

当 tableView 在编辑模式之间切换时,我试图在 backBarButtonItem 和取消按钮之间获得流畅的动画。

- (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]; 尝试了各种方法,但所有生成的动画都有些不稳定。

任何人对此有任何想法,上面的代码适用于两个 UIBarButtonItem,但与 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];
    }
}

【问题讨论】:

    标签: ios uitableview animation uibarbuttonitem


    【解决方案1】:

    将更改放入 UIView 动画块中:

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

    然后您可以调整动画的速度。

    【讨论】:

    • 感谢您的建议,这提供了从 barButton 到 backButton 的合适淡入淡出动画,但在另一个方向上提供了奇怪的缩放动画。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多