贪吃蛇

//

//  ViewController.m

//  119textSix

//

//  Created by FuHeXiang on 16/1/19.

//  Copyright (c) 2016年 XinZhongZhi. All rights reserved.

//

 

#import "ViewController.h"

#import "UIView+Ext.h"

NSInteger const Ktag=100;

//宏定义 长 宽

#define DEF_SCR_WIDTH [UIScreen maiScreen].bound.size.width

#define DEF_SCR_HEIGHT [UIScreen maiScreen].bound.size.height

@interface ViewController ()

{

    UIView * _redView;

 

}

@property (weak, nonatomic) IBOutlet UILabel *label;

@property (weak, nonatomic) IBOutlet UIButton *ladel;

 

@end

 

@implementation ViewController

- (IBAction)botton:(id)sender {

    //这个实现的是红色方块向斜下方慢慢移动

    self. label .text =@"已经打开";

                [UIView animateWithDuration:2 delay:0 usingSpringWithDamping:5 initialSpringVelocity:20 options:UIViewAnimationOptionCurveEaseInOut animations:^{

                    CGRect frame=_redView.frame;

                    frame.origin.y +=10;

                    frame.origin.x +=10;

                    _redView .frame =frame;

                    _redView .tag +=10;

                    _redView .bottom;

                } completion:nil];

    

    

    //功能分别是 是持续时间  延迟  弹性  速度

    [UIView animateWithDuration:2 delay:0 usingSpringWithDamping:0.7 initialSpringVelocity:20 options:UIViewAnimationOptionCurveEaseInOut animations:^{

        _redView .frame = CGRectMake(100, 100, 100, 100);

    } completion:^(BOOL finished) {

        if (finished) {

            [UIView animateWithDuration:3 delay:0 usingSpringWithDamping:5 initialSpringVelocity:10 options:UIViewAnimationOptionCurveEaseOut animations:^{

                _redView .frame=CGRectMake(100, 100, 100, 100);

                _redView .backgroundColor =[UIColor yellowColor ];

                _redView .alpha=0.2;

            } completion:nil];

        }

        

    }];

}

int i=0;

-(void)text:(NSTimer *)timer{

 

    //1 获取传递的时间

    //timer.userinfo

    // 2 可以让时间停止

    i++;

    if (i%5==0) {

        [timer invalidate];

    }

    NSLog(@"%d",i);

 

}

 

- (void)viewDidLoad

{

    [super viewDidLoad];

    //下面创建一个方块

    _redView=[[UIView alloc ] init ];

    _redView .frame = CGRectMake(0, 0, 100, 100);

    [self.view addSubview:_redView];

    _redView .backgroundColor = [UIColor redColor];

    

    //创建第二个方块

    UIView * view = [[UIView alloc ]init ];

    view .frame=CGRectMake(30, 30, 100, 100);

    [self .view addSubview:view];

    view.backgroundColor =[UIColor greenColor];

    

    //创建第三个方块

    UIView * view2 = [[UIView alloc] init];

    view2 .frame =CGRectMake(60, 60, 100, 100);

    [self .view addSubview:view2];

    view2.backgroundColor = [UIColor blueColor];

    

    //下面设置新建小方块来循环的贪吃蛇

    //UIView * view3= [[UIView alloc ] init];

   // view3 .frame =CGRectMake(150,200, 20, 20);

   //把头一个小方块变成其他颜色

       for (int i=0; i<10; i++) {

        UIView * view3=[[UIView alloc] initWithFrame:CGRectMake(i*10+100, 0+200, 20, 20)];

          [self .view addSubview:view3];

         view3 .backgroundColor =[UIColor blackColor];

        view3 .tag = i +100;

        

    }

    UIView *view3=[self .view viewWithTag:Ktag+9];

    view3 .backgroundColor =[ UIColor  yellowColor];

    

    _redView =[[UIView alloc] initWithFrame: CGRectMake((DEF_SCR_WIDTH/2-100), DEF_SCR_HEIGHT/2-50, 200, 100)];

    _redView .backgroundColor =[UIColor redColor ];

    

}

 

 

- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

   

}

 

@end

 

posted @ 2016-01-19 17:59  专注博客园三十年  阅读(170)  评论(0编辑  收藏  举报