欢迎来到代码驿站!

iOS代码

当前位置:首页 > 移动开发 > iOS代码

iOS自带动画效果的实例代码

时间:2021-04-17 09:54:48|栏目:iOS代码|点击:

 1.普通动画:

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:2];
frame.origin.x += 150;
[img setFrame:frame];
[UIView commitAnimations];

2.连续动画(一系列图像):

NSArray *myImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"myImage1.png"],
[UIImage imageNamed:@"myImage2.png"],
[UIImage imageNamed:@"myImage3.png"],
[UIImage imageNamed:@"myImage4.png"], nil];
UIImageView *myAnimatedView = [[UIImageView alloc] initWithFrame:[self bounds]];
myAnimatedView.animationImages = myImage;
myAnimatedView.animationRepeatCount = 0;
[myAnimatedView startAnimating];
[self addSubview:myAnimatedView];
[my AnimatedView release];

3.CATransition Public API:

CATransition *animation = [CATransition animation];
animation.duration = 0.5f;
animation.timingFunction = UIViewAnimationCurveEaseInOut;
animation.fillMode = KCAFillModeForwards;
//各种动画效果
/*
KCATransitionFade;
KCATransitionMoveIn;
KCATransitionPush;
KCATransitionReveal;
*/
/*
KCATransitionFromeRight;
KCATransitionFromLeft;
KCATransitionFormTop;
kCATransitionFromButtons;
*/
//各种组合
animation.type = KCATransitionPush;
animation.subtype = KCATransitionFromRight;
[self.view.layer addAnimation:animation forKey:@"animation"];

4.UIView Animations动画:

[UIView beginAnimations:@"animationID" context:nil];
[UIView setAnimationDuration:0.5f];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationRepeatAutoreverses:NO];
//以下四种效果
/*
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFormLeft forView:self.view cache:YES];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFormRight forView:self.view cache:YES];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:YES];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.view cache:YES];
*/

5.嵌套使用,先变大再消失

[UIView animateWithDuration:1.25 aniamtions:^{
    CGAffineTransform newTRansform = CGAffineTransformMakeScale(1.2, 1.2);
    [firstImageView setTransform:newTransform];
    [secondImageView setTransform:newTransform];
    completion:^(BOOL finished){
        [UIView animateWithDuration:1.2 animations:^{
            [firstImageView setAlpha:0];
            [secondImageView setAlpha:0];
        }
        completion:^(BOOL finished){
            [firstImageView removeFromSuperview];
            [secondImageView removeFromSuperview];
        }
        ];
    }
];

上一篇:iOS开发之自定义UITextField的方法

栏    目:iOS代码

下一篇:详解iOS Project和Targets配置

本文标题:iOS自带动画效果的实例代码

本文地址:http://www.codeinn.net/misctech/103286.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有