iOS 动画(3)

本文介绍如何使用UIView和CATransition实现多种视图切换动画效果,包括翻页、移入、揭开等,并提供了具体的代码示例。

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

CATransition动画设置两个UIView

    UIView *magentaView =[[UIView alloc]initWithFrame:self.view.bounds];
    magentaView.backgroundColor =[UIColor magentaColor];
    [self.view addSubview:magentaView];
    UIView * gtayView =[[UIView alloc]initWithFrame:self.view.bounds];
    gtayView.backgroundColor =[UIColor lightGrayColor];
    [self.view addSubview:gtayView];


//提交
-(void)add{
    //    开始动画
    [UIView beginAnimations:@"animation" context:nil];
    [UIView setAnimationDuration:1.0];
    [UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.view cache:YES];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [self.view exchangeSubviewAtIndex:0 withSubviewAtIndex:1];

    //     提交动画
    [UIView commitAnimations];


}
//翻页
-(void)curl
{
    //    开始动画
    [UIView beginAnimations:@"animation" context:nil];
    [UIView setAnimationDuration:1.0f];
    [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:YES];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [self.view exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
    //     提交动画
    [UIView commitAnimations];
}
//移入
-(void)move
{
    CATransition *strasiton =[CATransition animation];
    strasiton.duration = 2.0f;
     //    使用kCATransitionMoveIn动画
    strasiton.type = kCATransitionMoveIn;
    //      指定动画方向,从左向右
    strasiton.subtype = kCATransitionFromLeft;
    [self.view.layer addAnimation:strasiton forKey:@"animation"];
    [self.view exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
}
//揭开
-(void)reveal
{
    
    CATransition *strasiton =[CATransition animation];
    strasiton.duration = 2.0f;
    //    使用kCATransitionReveal动画
    strasiton.type = kCATransitionReveal;
     strasiton.subtype = kCATransitionFromTop;
    [self.view.layer addAnimation:strasiton forKey:@"animation"];
    [self.view exchangeSubviewAtIndex:0 withSubviewAtIndex:1];

}
//立方体
-(void)cube
{
    CATransition *trasiton =[CATransition animation];
    trasiton.duration = 2.0f;
    trasiton.type = @"cube";
    trasiton.subtype = kCATransitionFromLeft;
    [self.view.layer addAnimation:trasiton forKey:@"animation"];
    [self.view exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
}
//吸入
-(void)suck
{
    CATransition *trasiton =[CATransition animation];
    trasiton.duration = 2.0f;
    trasiton.type = @"suckEffect";
    trasiton.subtype = kCATransitionFromLeft;
    [self.view.layer addAnimation:trasiton forKey:@"animation"];
    [self.view exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
}
//翻转
-(void)oglFlip
{
    CATransition *trasiton =[CATransition animation];
    trasiton.duration = 2.0f;
    trasiton.type = @"oglFlip";
    trasiton.subtype = kCATransitionFromLeft;
    [self.view.layer addAnimation:trasiton forKey:@"animation"];
    [self.view exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
    
}
//水波
-(void)ripple
{
    CATransition *trasiton =[CATransition animation];
    trasiton.duration = 2.0f;
    trasiton.type = @"rippleEffect";
    trasiton.subtype = kCATransitionFromLeft;
    [self.view.layer addAnimation:trasiton forKey:@"animation"];
    [self.view exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值