首页 > 其他 > 详细

(5.20)step计数触发定时器--雪花效果

时间:2014-05-21 18:38:52      阅读:358      评论:0      收藏:0      [点我收藏+]

//  mainViewController.m
//  雪花
//
//  Created by pg on 14-5-20.
//  Copyright (c) 2014年 mqd. All rights reserved.
//

#import "mainViewController.h"

//时钟刷新步长
static long step;

@interface mainViewController ()
//游戏时钟
@property(strong,nonatomic)CADisplayLink *gameTime;
//雪花图像
@property(strong,nonatomic)UIImage *snowImage;

@end

@implementation mainViewController
- (void)viewDidLoad

{

    [super viewDidLoad];
    //设置背景颜色
    [self.view setBackgroundColor:[UIColor blackColor]];
    
    //实例化雪花
    self.snowImage = [UIImage imageNamed:@"雪花.png"];
   //设置时钟步长
     step = 0;
    //1,实例化游戏时钟
    self.gameTime = [CADisplayLink displayLinkWithTarget:self selector:@selector(step)];
    //2,添加到主运行循环
    
    [self.gameTime addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode];

}
    
-(void)step{
    step++;
    //每秒下十个
    if (step % 3 == 0) {
        //实例化uiimageview
        UIImageView *imageView = [[UIImageView alloc] initWithImage:self.snowImage];
        
            //将uiimage添加到视图
        [self.view addSubview:imageView];
        //随机位子
        CGFloat x = arc4random_uniform(320);
        CGFloat y = - self.snowImage.size.height / 2;
        [imageView setCenter:CGPointMake(x, y)];
       
        
        
        //设置雪花大小
        CGFloat r = arc4random_uniform(15) +10;
        [imageView setBounds:CGRectMake(0, 0, r, r)];
        //实现uiview,动画结束后,删除uiimage
        [UIView animateWithDuration:3.0f animations:^{
            
            
        [imageView setCenter:CGPointMake(arc4random_uniform(320), 450+arc4random_uniform(10)) ];
            
            //设置雪花旋转180度
            [imageView setTransform:CGAffineTransformMakeRotation(M_PI)];
            
            //设置雪花透明
            [imageView setAlpha:0.3f];
            
        }completion:^(BOOL finished) {
            [imageView removeFromSuperview];
        }];
        
         }
    
         }


@end

(5.20)step计数触发定时器--雪花效果,布布扣,bubuko.com

(5.20)step计数触发定时器--雪花效果

原文:http://www.cnblogs.com/modingding/p/3740191.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!