首页 > 其他 > 详细

变形方块

时间:2014-11-26 23:53:02      阅读:317      评论:0      收藏:0      [点我收藏+]
// // ViewController.m // 变形方块 // // Created by 卿鹏 on 14-11-26. // Copyright (c) 2014年 qingpeng. All rights reserved. // #import "ViewController.h" @interface ViewController () { NSMutableArray *array; UIView *v; } @end @implementation ViewController int m1[16][4][4] ={ {{0,0,0,0},{0,1,1,0},{0,1,1,0},{0,0,0,0}}, {{0,0,0,0},{1,1,1,1},{0,0,0,0},{0,0,0,0}}, {{0,0,0,0},{1,1,0,0},{0,1,1,0},{0,0,0,0}}, {{0,0,0,0},{0,0,1,1},{0,1,1,0},{0,0,0,0}}, {{0,0,0,0},{0,1,0,0},{1,1,1,0},{0,0,0,0}}, {{0,0,0,0},{0,1,1,1},{0,0,1,0},{0,0,0,0}}, {{1,0,0,0},{1,1,0,0},{1,0,0,0},{0,0,0,0}}, {{0,0,0,1},{0,0,1,1},{0,0,0,1},{0,0,0,0}}, {{1,0,0,0},{1,0,0,0},{1,0,0,0},{1,1,0,0}}, {{0,0,0,1},{0,0,0,1},{0,0,0,1},{0,0,1,1}}, {{1,1,0,0},{1,0,0,0},{1,0,0,0},{1,0,0,0}}, {{0,0,1,1},{0,0,0,1},{0,0,0,1},{0,0,0,1}}, {{0,1,0,0},{1,1,0,0},{1,0,0,0},{0,0,0,0}}, {{0,0,1,0},{0,0,1,1},{0,0,0,1},{0,0,0,0}}, {{0,0,0,0},{1,1,1,1},{0,0,0,0},{0,0,0,0}}, {{0,0,0,0},{0,1,1,0},{0,1,1,0},{0,0,0,0}} }; int n[4][4] = {{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0}}; - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. array = [[NSMutableArray alloc] init]; for(int i=0;i<16; i++) { int row = i % 4; int column = i / 4 ; v = [[UIView alloc] initWithFrame:CGRectMake(row*42+100, column*42+150, 40, 40)]; [array addObject:v];//添加一个OC中的View对象 [self.view addSubview:v]; } for(int x=0;x<4;x++)//初始化界面 { for(int y=0; y<4; y++) { UIView *k = array[x*4+y];//从数组中取出UIview if (n[x][y]) { k.backgroundColor = [UIColor blueColor]; } else { k.backgroundColor = [UIColor grayColor]; } } } } - (IBAction)didButton:(UIButton *)sender { static int n=0; if (n==15) { n = 0; } else { n ++; } for(int x=0;x<4;x++) { for(int y=0; y<4; y++) { UIView *k = array[x*4+y];//从数组中取出UIview if (m1[n][x][y]) { k.backgroundColor = [UIColor blueColor]; } else { k.backgroundColor = [UIColor grayColor]; } } } } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end

变形方块

原文:http://www.cnblogs.com/qingpeng-ios/p/4125256.html

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