iOS动画

iOS页面切换动画实现方式。
1.使用[color=darkred]UIView animateWithDuration:animations:completion[/color]方法

[UIView animateWithDuration:0.2f animations:^{
detail.view.frame = CGRectMake(0, 0, detail.view.frame.size.width, detail.view.frame.size.height);
} completion:^(BOOL finished) {
UITableViewCell *cell = [articleTable cellForRowAtIndexPath:idx];
cell.backgroundColor = [UIColor clearColor];
}];

2.使用UIView beginAnimations:context和UIView commitAnimations方法

[UIView beginAnimations:nil context: nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];//指定动画曲线
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.view cache:YES];//指定动画方式为卷帘向下,类似的动画切换方式有CurlUp、FlipFromLeft、FlipFromRight,对应Apple Developer Documents中的枚举结构如下
//UIViewAnimationTransition
//Specifies a transition to apply to a view in an animation block.
//typedef enum {
// UIViewAnimationTransitionNone,
// UIViewAnimationTransitionFlipFromLeft,
// UIViewAnimationTransitionFlipFromRight,
// UIViewAnimationTransitionCurlUp,
// UIViewAnimationTransitionCurlDown,
//} UIViewAnimationTransition;

//要动画改变的属性
self.view.alpha = 0.0;//动画改变透明度
self.view.frame = CGRectMake(10, 10, 50, 50);//动画将视图改变到指定位置指定大小
[self.view exchangeSubviewAtIndex:1 withSubviewAtIndex:0];

[UIView commitAnimations];//提交动画


3.使用QuartzCore框架中的CATransition

CATransition *animation = [CATransition animation];
animation.delegate = self;
animation.duration = kDuration;
animation.timingFunction = UIViewAnimationCurveEaseInOut;//动画的开始与结束的快慢
animation.type = kCATransitionFade;//指定动画方式为Fade渐隐消去、类似还有kCATransitionPush、kCATransitionReveal、kCATransitionMoveIn、@"cube"、@"suckEffect"、@"oglFlip"、@"rippleEffect"、@"pageCurl"、@"pageUnCurl"、@"cameraIrisHollowOpen"、@"cameraIrisHollowClose"等,
//pageCurl 向上翻一页
//pageUnCurl 向下翻一页
//rippleEffect 滴水效果
//suckEffect 收缩效果,如一块布被抽走
//cube 立方体效果
//oglFlip 上下翻转效果
//cameraIrisHollowOpen 相机打开效果
//cameraIrisHollowClose 相机关闭效果
Apple Developer Documents中介绍如下
//Common Transition Types
//These constants specify the transition types that can be used with the type property.
//NSString * const kCATransitionFade;
//NSString * const kCATransitionMoveIn;
//NSString * const kCATransitionPush;
//NSString * const kCATransitionReveal;
animation.subtype = kCATransitionFromLeft;//指定动画进行方向从左边开始,类似还有kCATransitionFromBottom、kCATransitionFromRight、kCATransitionFromTop,Apple Developer Documents中介绍如下
//Common Transition Subtypes
//These constants specify the direction of motion-based transitions. They are used //with the subtype property.
//NSString * const kCATransitionFromRight;
//NSString * const kCATransitionFromLeft;
//NSString * const kCATransitionFromTop;
//NSString * const kCATransitionFromBottom;

[self.view exchangeSubviewAtIndex:1 withSubviewAtIndex:0];
[[self.view layer] addAnimation:animation forKey:@"animation"];
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值