zoukankan      html  css  js  c++  java
  • 变形方块

    // // 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
  • 相关阅读:
    使用 SVN Hook 实现服务器端代码自动更新
    在Windows下配置svn服务端钩子程序(部分)
    @RequestParam,@PathParam,@PathVariable等注解区别
    @ConditionalOnProperty 详解
    Spring MVC之@RequestParam @RequestBody @RequestHeader 等详解
    Ajax中Delete请求参数 后台无法获取的解决方法(Restful风格)
    原生JS和jQuery版实现文件上传功能
    捡芝麻与捡西瓜
    在行动中思考
    日常相关的标准技术和组织
  • 原文地址:https://www.cnblogs.com/qingpeng-ios/p/4125256.html
Copyright © 2011-2022 走看看