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

 更新时间:2016年12月27日 10:21:56   作者:绍棠  
本文给大家分享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自带动画效果的实例代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对脚本之家网站的支持!

相关文章

  • UITableView 实现汽车品牌(demo)

    UITableView 实现汽车品牌(demo)

    UITableView堪称UIKit里面最复杂的一个控件了,使用起来不算难,但是要用好并不容易,当使用的时候我们必须要考虑到后台数据的设计,tableViewCell的设计和重用以及tableView的效率等问题,下面小编通过UITableView 实现汽车品牌,需要的朋友可以参考下
    2015-08-08
  • iOS内存管理中引用计数的学习

    iOS内存管理中引用计数的学习

    文章给大家分享了关于iOS内存管理中引用计数的相关知识点,对此有需要的朋友可以跟着学习下。
    2018-05-05
  • 10个非常实用的iOS小技巧

    10个非常实用的iOS小技巧

    这篇文章主要为大家详细介绍了10个非常实用的iOS小技巧,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2017-03-03
  • iOS自定义UIBarButtonItem的target和action示例代码

    iOS自定义UIBarButtonItem的target和action示例代码

    这篇文章主要给大家介绍了关于iOS自定义UIBarButtonItem的target和action的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面来一起学习学习吧
    2019-02-02
  • iOS开发之tableView实现左滑删除功能

    iOS开发之tableView实现左滑删除功能

    我们在使用一些应用的时候,在滑动一些联系人的某一行的时候,会出现删除、置顶、更多等等的按钮,下面这篇文章主要就介绍了iOS用tableView实现左划删除功能的方法,有需要的朋友们可以参考借鉴,下面来一起看看吧。
    2017-01-01
  • iOS 控件封装(又名拧螺丝)之排序按钮的开发

    iOS 控件封装(又名拧螺丝)之排序按钮的开发

    排序按钮是实际开发中比较常见的一种控件,这篇文章主要介绍了iOS 开发之排序按钮,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2018-12-12
  • IOS实现百度地图自定义大头针和气泡样式

    IOS实现百度地图自定义大头针和气泡样式

    这篇文章主要介绍了 IOS百度地图自定义大头针和气泡的实例代码,非常不错,具有参考借鉴价值,需要的朋友参考下
    2016-12-12
  • iOS开发之时间戳(或date)转字符串的实例代码

    iOS开发之时间戳(或date)转字符串的实例代码

    这篇文章主要介绍了iOS开发之时间戳(或date)转字符串的实例代码,需要的朋友可以参考下
    2017-10-10
  • IOS多线程编程的3种实现方法

    IOS多线程编程的3种实现方法

    这篇文章主要介绍了IOS多线程编程的3种实现方法的相关资料,需要的朋友可以参考下
    2015-11-11
  • iOS App开发中UIViewController类的使用教程

    iOS App开发中UIViewController类的使用教程

    UIViewController是iOS中控制视图的关键所在,这里我们将针对UIViewController的声明周期与主要属性和方法,来总结iOS App开发中UIViewController类的使用教程
    2016-07-07

最新评论