animaiton各种好玩动画·2

@property (nonatomic) CATransition *transition;//全局变量

  • aa {

pragma 正方体效果向上翻转

CATransition *transtion = [CATransition animation];
[transtion setStartProgress:0.5];
[transtion setEndProgress:0.6];
transtion.duration = 5;
[transtion setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]];
[transtion setType:@"cube"];
[transtion setSubtype:kCATransitionFromTop];
[_imageView.layer addAnimation:transtion forKey:@"transtionKey"];
transtion.delegate = self; //代理

   _transition = [CATransition animation];
    [transtion setStartProgress:0.5];
    [transtion setEndProgress:0.6];
    _transition.duration = 2;
    [_transition setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]];
    [_transition setType:@"cube"];
 [_transition setDelegate:self];//代理写在前面,写在最后面不会调用代理方法!!
    [_transition setSubtype:kCATransitionFromTop];
    [_imageView.layer addAnimation:_transition forKey:@"transtionKey"];

pragma 从下向上推出

CATransition *transtion = [CATransition animation];
//            [transtion setStartProgress:0.5];
//            [transtion setEndProgress:0.6];
transtion.duration = 5;
[transtion setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]];
[transtion setType:kCATransitionPush];
[transtion setSubtype:kCATransitionFromTop];
[_imageView.layer addAnimation:transtion forKey:@"animationKey"];

pragma 从小向上揭走

CATransition *transtion = [CATransition animation];
//            [transtion setStartProgress:0.5];
//            [transtion setEndProgress:0.6];
transtion.duration = 5;
[transtion setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]];
[transtion setType:kCATransitionReveal];
[transtion setSubtype:kCATransitionFromTop];
[_imageView.layer addAnimation:transtion forKey:@"transtionKey"];

pragma 从下向上覆盖

CATransition *transtion = [CATransition animation];
//            [transtion setStartProgress:0.5];
//            [transtion setEndProgress:0.6];
transtion.duration = 5;
[transtion setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]];
[transtion setType:kCATransitionMoveIn];
[transtion setSubtype:kCATransitionFromTop];
[_imageView.layer addAnimation:transtion forKey:@"transtionKey"];

pragma 一张图片覆盖另一张图片

CATransition *transtion = [CATransition animation];
//            [transtion setStartProgress:0.5];
//            [transtion setEndProgress:0.6];
transtion.duration = 5;
[transtion setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];
                              [transtion setType:kCATransitionFade];
                              [transtion setSubtype:kCATransitionFromTop];
                              [_imageView setImage:[UIImage imageNamed:@"仪表盘2"]];
                              [_imageView.layer addAnimation:transtion forKey:@"animationkey"];

pragma 抽走

CATransition *transtion = [CATransition animation];
//            [transtion setStartProgress:0.5];
//            [transtion setEndProgress:0.6];
transtion.duration = 5;
[transtion setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]];
[transtion setType:@"suckEffect"];
[transtion setSubtype:kCATransitionFromTop];
[_imageView.layer addAnimation:transtion forKey:@"transtionKey"];

pragma 绕x轴翻转

CATransition *transtion = [CATransition animation];
//            [transtion setStartProgress:0.5];
//            [transtion setEndProgress:0.6];
transtion.duration = 5;
[transtion setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]];
[transtion setType:@"oglFlip"];
[transtion setSubtype:kCATransitionFromTop];
[_imageView.layer addAnimation:transtion forKey:@"transtionKey"];

pragma 波纹效果

// CATransition *transtion = [CATransition animation];
// [transtion setStartProgress:0.5];
// [transtion setEndProgress:0.6];
transtion.duration = 5;
[transtion setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]];
[transtion setType:@"rippleEffect"];
[transtion setSubtype:kCATransitionFromTop];
[_imageView.layer addAnimation:transtion forKey:@"transtionKey"];

pragma 开镜头

CATransition *transtion = [CATransition animation];
//            [transtion setStartProgress:0.5];
//            [transtion setEndProgress:0.6];
transtion.duration = 5;
[transtion setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]];
[transtion setType:@"cameraIrisHollowOpen"];
[transtion setSubtype:kCATransitionFromTop];
[_imageView.layer addAnimation:transtion forKey:@"transtionKey"];

pragma 关镜头

CATransition *transtion = [CATransition animation];
//            [transtion setStartProgress:0.5];
//            [transtion setEndProgress:0.6];
transtion.duration = 5;
[transtion setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]];
[transtion setType:@"cameraIrisHollowClose"];
[transtion setSubtype:kCATransitionFromTop];
[_imageView.layer addAnimation:transtion forKey:@"transtionKey"];

pragma 缩放

CABasicAnimation *basic = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
[basic setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];
[basic setFromValue:[NSNumber numberWithFloat:1]];
[basic setToValue:[NSNumber numberWithFloat:.3]];
[basic setDuration:2];
//[basic setDelegate:self];
[_imageView.layer addAnimation:basic forKey:@"animationKey"];

pragma 透明

CABasicAnimation *basic1 = [CABasicAnimation animationWithKeyPath:@"opacity"];
[basic1 setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];
[basic1 setFromValue:[NSNumber numberWithFloat:1]];
[basic1 setToValue:[NSNumber numberWithFloat:.3]];
[basic1 setDuration:2];
[_imageView.layer addAnimation:basic1 forKey:@"animationKey"];

pragma 边框效果

CAKeyframeAnimation *keyframe = [CAKeyframeAnimation animationWithKeyPath:@"borderWidth"];
keyframe.values = [NSArray arrayWithObjects:[NSNumber numberWithFloat:0],
                   [NSNumber numberWithFloat:5],
                   [NSNumber numberWithFloat:10],
                   [NSNumber numberWithFloat:15],nil];
keyframe.repeatCount = MAXFLOAT;
keyframe.autoreverses = YES;
keyframe.duration = 2;
[_imageView.layer addAnimation:keyframe forKey:@"animationKey"];

pragma 移动位置

UIBezierPath *path = [UIBezierPath bezierPath];
//[path moveToPoint:image.frame.origin];
[path moveToPoint:CGPointMake(_imageView.frame.origin.x + _imageView.frame.size.width/2, _imageView.frame.origin.y + _imageView.frame.size.height/2)];
[path addLineToPoint:CGPointMake(_imageView.frame.origin.x + _imageView.frame.size.width/2,400)];
[path addLineToPoint:CGPointMake(20, 400)];
CAKeyframeAnimation *keyframe1 = [CAKeyframeAnimation animationWithKeyPath:@"position"];
keyframe1.path = path.CGPath;
keyframe1.duration = 2;
[_imageView.layer addAnimation:keyframe1 forKey:@"animationKey"];

pragma 动画组

CAAnimationGroup *group = [CAAnimationGroup animation];
CABasicAnimation *basic2 = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
[basic2 setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];
[basic2 setFromValue:[NSNumber numberWithFloat:1]];
[basic2 setToValue:[NSNumber numberWithFloat:.3]];
CAKeyframeAnimation *keyframe2 = [CAKeyframeAnimation animationWithKeyPath:@"transform.rotation.x"];
keyframe2.values = [NSArray arrayWithObjects:[NSNumber numberWithFloat:0],[NSNumber numberWithFloat:M_PI], nil];
[group setDuration:2];
[group setAnimations:[NSArray arrayWithObjects:basic2,keyframe2, nil]];
[_imageView.layer addAnimation:group forKey:@"animationKey"];

pragma 自动转圈

CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
animation.toValue = @( - M_PI * 2);
animation.duration = 3;
animation.repeatCount = MAXFLOAT;
[_imageView.layer addAnimation:animation forKey:@"rotationZ"];
}

  • sender {
    [UIView beginAnimations:@"animationID" context:nil];
    [UIView setAnimationDuration:4];
    [UIView setAnimationCurve:UIViewAnimationCurveLinear];
    [UIWindow setAnimationsEnabled:YES];
    // [UIView setAnimationRepeatAutoreverses:YES]; //自动恢复
    [UIView setAnimationDidStopSelector:@selector(fasd)]; //动画结束完成的事件

pragma 4个方向的翻页

[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:_imageView cache:YES];//向上翻页

// [UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:_imageView cache:YES];//向下翻页
// [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:_imageView cache:YES];//向左翻页
// [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:_imageView cache:YES];//向右翻页
[UIView setAnimationDelegate:self]; //设置代理后,执行-(void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
[UIView commitAnimations];
}

pragma 代理方法

  • (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag{
    self.imageView.image = [UIImage imageNamed:@"仪表盘2"];
    }
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 206,126评论 6 481
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 88,254评论 2 382
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 152,445评论 0 341
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 55,185评论 1 278
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 64,178评论 5 371
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,970评论 1 284
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,276评论 3 399
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,927评论 0 259
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 43,400评论 1 300
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,883评论 2 323
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,997评论 1 333
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,646评论 4 322
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,213评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,204评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,423评论 1 260
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 45,423评论 2 352
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,722评论 2 345

推荐阅读更多精彩内容

  • 在iOS实际开发中常用的动画无非是以下四种:UIView动画,核心动画,帧动画,自定义转场动画。 1.UIView...
    请叫我周小帅阅读 3,078评论 1 23
  • 在iOS中随处都可以看到绚丽的动画效果,实现这些动画的过程并不复杂,今天将带大家一窥ios动画全貌。在这里你可以看...
    每天刷两次牙阅读 8,465评论 6 30
  • 在iOS中随处都可以看到绚丽的动画效果,实现这些动画的过程并不复杂,今天将带大家一窥iOS动画全貌。在这里你可以看...
    F麦子阅读 5,094评论 5 13
  • 先看看CAAnimation动画的继承结构 CAAnimation{ CAPropertyAnimation { ...
    时间不会倒着走阅读 1,638评论 0 1
  • 如果想让事情变得顺利,只有靠自己--夏尔·纪尧姆 上一章介绍了隐式动画的概念。隐式动画是在iOS平台创建动态用户界...
    夜空下最亮的亮点阅读 1,923评论 0 1