自定义简单的转场动画

这篇博客探讨了如何在iOS应用中实现点击导航栏按钮时,自定义视图控制器之间的转场动画,详细讲解了转场过程及动画效果的实现方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在视图控制器中点击导航栏按钮,实现导航栏按钮和页面的转场动画

//设置点击导航栏按钮事件
- (void)buttonAction:(UIButton *)button {

    //取得导航项的父视图
    UIView *superView = self.navigationItem.rightBarButtonItem.customView;
    UIButton *button1 = (UIButton *)[superView viewWithTag:101];
    UIButton *button2 = (UIButton *)[superView viewWithTag:102];

    //将按钮的hidden值取反
    button1.hidden = !button1.hidden;
    button2.hidden = !button2.hidden;

    //将视图的hidden值取反
    _tableView.hidden = !_tableView.hidden;
    _posterView.hidden = !_posterView.hidden;

    //设置转场动画的值
    UIViewAnimationTransition animation = button1.hidden ? UIViewAnimationTransitionFlipFromLeft : UIViewAnimationTransitionFlipFromRight;
    [self flipViewWithAnimation:animation WithView:superView];
    [self flipViewWithAnimation:animation WithView:self.view];


}

//转场动画
- (void)flipViewWithAnimation:(UIViewAnimationTransition)animation WithView:(UIView *)view {

    //开始动画
    [UIView beginAnimations:nil context:nil];

    //动画时间
    [UIView setAnimationDuration:.35];

    //转场动画
    [UIView setAnimationTransition:animation forView:view cache:YES];

    //结束动画
    [UIView commitAnimations];
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值