首页 > 代码库 > 两个色块做的红绿灯
两个色块做的红绿灯
#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
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。