UIView 动画效果

需要在frameworks中添加QuartzCore.framework

在接口程序中加上头文件   #import <QuartzCore/QuartzCore.h>
方法一:CATransition

创建transition
    CATransition *transition = [CATransition animation];
    transition.duration = 1.0f;         /* 间隔时间*/
    transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; /* 动画的开始与结束的快慢*/
    transition.type = @"rippleEffect"; /* 各种动画效果*/
//@"cube" @"moveIn" @"reveal" @"fade"(default) @"pageCurl" @"pageUnCurl" @"suckEffect" @"rippleEffect" @"oglFlip"

    transition.subtype = kCATransitionFromRight;   /* 动画方向*/
    transition.delegate = self;

    [navigationController.view.layer /* 在想添加CA动画的VIEW的层上添加此代码*/addAnimation:transition forKey:nil];
//另外加一句,transition在申请时用的是+方法,所以不需要自己进行release ,在层上添加后不要认为retainCount已经+1,就还要release

//降效果作用到view的层上面
//实际上CATransition类中还有一个属性是removedOnCompletion,是此动画执行完后会自动remove,默认值为true

//降效果作用到view的层上面
[self.view.layer addAnimation:transition forKey:@"animation"];

方法二:UIView Animation
//开始一个动画块
[UIView beginAnimations:@"animationID" context:nil];
//设置动画块中的动画持续时间(用秒)
[UIView setAnimationDuration:0.5f];
//设置动画块中的动画属性变化的曲线
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
//变化曲线还有
(    UIViewAnimationCurveEaseInOut,         // slow at beginning and end
    UIViewAnimationCurveEaseIn,            // slow at beginning
    UIViewAnimationCurveEaseOut,           // slow at end
    UIViewAnimationCurveLinear)

//设置动画块中的动画效果是否自动重复播放。
[UIView setAnimationRepeatAutoreverses:NO];

//设置动画在动画模块中的重复次数
//setAnimationRepeatCount:
//设置动画消息的代理。
[UIView setAnimationDelegate:self];
[UIView
//设置消息给动画代理当动画开始的时候
setAnimationWillStartSelector:@selector(resizeAnimationWillStart:context:)];
[UIView
//设置消息给动画代理当动画停止的时候
setAnimationDidStopSelector:@selector(resizeAnimationDidStop:finished:context:)];


//将效果作用在指定的view
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES];

效果还有(UIViewAnimationTransitionFlipFromLeft,UIViewAnimationTransitionFlipFromRight,UIViewAnimationTransitionCurlUp,UIViewAnimationTransitionCurlDown)

//显示在最前面
[self.view exchangeSubviewAtIndex:1 withSubviewAtIndex:0];
//结束动画
[UIView commitAnimations];
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值