iOS:自定义后退按钮过渡动画

标签 ios objective-c animation uinavigationcontroller back

我有一个 View Controller (继承自 UIViewController),它具有用于呈现数据的自定义逻辑。它可以初始化一个新的 View Controller (相同类型)并使用 [self.navigationController pushViewController:next animated:NO] (接下来是新实例化的 Controller ),创建“ View 堆栈”体验,使用导航 Controller 默认后退按钮向上导航堆栈。

现在,在调用 pushViewController:animated: 之前,我可以通过调用 [self.navigationController.view.layer addAnimation:animation forKey:nil] 自定义过渡动画 .这对于“沿着堆栈向下”的 View 非常有效。

但是由于向上导航是使用默认后退按钮以默认方式完成的,因此使用的过渡是默认的左滑动画,这与我的自定义动画不匹配。

如何自定义这个过渡动画?

编辑:

我采纳了这里给出的想法并提出了:

UIBarButtonItem *back = [[UIBackButtonItem alloc] initWithTitle:@"\U000025C0\U0000FE0E" style:UIBarButtonItemStylePlain target:self action:@selector(back:)];
[self.navigationItem setLeftBarButtonItem:back]

过渡:

- (IBAction)back:(id)sender {
    CATransiotion *animation = [CATransition animation];
    animation.duration = 0.3f;
    amimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
    animation.type = kCATransitionMoveIn;
    [self.navigationController.view.layer addAnimation:animation forKey:nil];
    [self.navigationController popViewControllerAnimated:NO];
}

唯一的缺点是我愿意接受的新后退按钮的出现。

感谢您的回答:)

最佳答案

我想您必须制作自定义后退按钮,并将动画附加到它上面,例如。

- (IBAction) back:(id)sender
{       
    [UIView transitionWithView:self.navigationController.view
                      duration:0.5
                       options:UIViewAnimationOptionTransitionFlipFromLeft
                    animations:^{ [self.navigationController popViewControllerAnimated:NO]; }
                    completion:NULL];
}

关于iOS:自定义后退按钮过渡动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15598252/

相关文章:

ios - 删除前导逗号

iphone - iPhone SDK:从SQLite加载UITableView

ios - 动画延迟在 iOS 上无法正常工作,为什么?

ios - 两个设备是否具有相同的 'UUID'

ios - 应用程序终止时处理远程推送通知声音

objective-c - 为什么 addSubview 不显示?

javascript - 删除动画和显示全尺寸图像 HTML/CSS/JS 的问题

javascript - 使用 tween max 反向旋转

应用商店的 iOS Framework 协同设计

ios - 我可以在自定义 uitableviewcell 中使用滑动删除功能吗?