首页 > 代码库 > 两个色块做的红绿灯

两个色块做的红绿灯

#import "ViewController.h"@interface ViewController (){    UIView *view;    UIView *view0;    int i;}@end@implementation ViewController            - (void)viewDidLoad {    [super viewDidLoad];    view=[[UIView alloc]initWithFrame:CGRectMake(100, 100, 50, 50)];    view0=[[UIView alloc]initWithFrame:CGRectMake(200, 100, 50, 50)];    view.backgroundColor=[UIColor redColor];    view0.backgroundColor=[UIColor greenColor];    [self.view addSubview:view];    [self.view addSubview:view0];    [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(didclick:) userInfo:nil repeats:YES];}- (IBAction)didclick:(id)sender{    //    [UIView animateWithDuration:5 delay:4 options: UIViewAnimationOptionCurveEaseInOut                       animations:^{} completion:(void (^)(BOOL finished))completion{//        }];        [UIView animateWithDuration:1 delay:0 options:UIViewAnimationOptionAllowUserInteraction animations:^{        NSLog(@"XXXXXXX");        if (i%2==0)        {view.frame=CGRectMake(100, 100, 100, 100);}        else        {            view0.frame=CGRectMake(200, 100, 100, 100);        }    } completion:^(BOOL finished) {        NSLog(@"FINISH");        view.frame=CGRectMake(100, 100, 50, 50);        view0.frame=CGRectMake(200, 100, 50, 50);        i++;    }];}- (void)didReceiveMemoryWarning {    [super didReceiveMemoryWarning];    // Dispose of any resources that can be recreated.}@end