码迷,mamicode.com
首页 > 其他好文 > 详细

161设置在屏幕中的动画延迟(扩展知识:普通操作和代码块操作实现动画效果)

时间:2015-06-17 18:09:41      阅读:94      评论:0      收藏:0      [点我收藏+]

标签:

效果如下:

技术分享

ViewController.h

1 #import <UIKit/UIKit.h>
2 
3 @interface ViewController : UIViewController
4 @property (strong, nonatomic) UIImageView *imgVAnimation;
5 
6 @end

ViewController.m

 1 #import "ViewController.h"
 2 
 3 @interface ViewController ()
 4 - (void)layoutUI;
 5 - (void)animationByNormalOperation;
 6 - (void)animationByBlockOperation;
 7 @end
 8 
 9 @implementation ViewController
10 
11 - (void)viewDidLoad {
12     [super viewDidLoad];
13     
14     [self layoutUI];
15 }
16 
17 - (void)didReceiveMemoryWarning {
18     [super didReceiveMemoryWarning];
19     // Dispose of any resources that can be recreated.
20 }
21 
22 - (void)layoutUI {
23     self.view.backgroundColor = [UIColor blackColor];
24     NSString *path = [[NSBundle mainBundle] pathForResource:@"Star" ofType:@"png"];
25     _imgVAnimation = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:path]];
26     _imgVAnimation.frame = CGRectMake(0, 0, 20.0, 20.0);
27     _imgVAnimation.center = CGPointMake(10.0, 30.0);
28     [self.view addSubview:_imgVAnimation];
29 }
30 
31 - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
32     _imgVAnimation.center = CGPointMake(10.0, 30.0);
33     
34     [self animationByBlockOperation];
35 }
36 
37 /**
38  *  普通操作设置动画
39  */
40 - (void)animationByNormalOperation {
41     [UIView beginAnimations:nil context:NULL];
42     [UIView setAnimationDuration:1.5]; //设置动画持续时间;默认值为0.2s
43     [UIView setAnimationDelay:1.0]; //设置动画延迟时间;默认值为0.0s
44     [UIView setAnimationRepeatCount:5.0]; //设置动画播放重复次数;默认值为0,表示不循环只执行一次(区别于UIImageView.animationRepeatCount=0为无限循环)
45     _imgVAnimation.center = CGPointMake(220, 400);
46     [UIView commitAnimations];
47 }
48 
49 /**
50  *  代码块设置动画
51  */
52 - (void)animationByBlockOperation {
53     [UIView animateWithDuration:1.5
54                           delay:1.0
55                         options:UIViewAnimationOptionTransitionNone
56                      animations:^{
57                          [UIView setAnimationRepeatCount:5.0];
58                          _imgVAnimation.center = CGPointMake(220, 400);
59                      } completion:^(BOOL finished) {
60                          
61                      }];
62 }
63 
64 @end

 

161设置在屏幕中的动画延迟(扩展知识:普通操作和代码块操作实现动画效果)

标签:

原文地址:http://www.cnblogs.com/huangjianwu/p/4583864.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!