iPhoneデザインi

デザイン「あ」に簾みたいにぶら下がっているプレートをくるくる回して「あ」に見せるのがあったので、アルファベットの「i」でそんなかんじのiPhoneアプリを描いてみる。


動作イメージ
XcodeからiOS7 iPhone Simulatorで動かすとこんな感じになります。

サンプルコード

#import “ViewController.h”

@interface ViewController ()

@property (strong, nonatomic) UILabel *iLabel;

@end

@implementation ViewController

– (void)viewDidLoad

{

    [super viewDidLoad];

    self.view.backgroundColor = [UIColor blackColor];

    [self createI];

}

– (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

{

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

        float x = (i%15) * 20 + 20;

        float y = (i/15) * 20 + 80;

        UIView *plate = [self createPlate];

        plate.center = CGPointMake(x, y);

        

        UIColor *color = [self colorOfPoint:CGPointMake(x,y)];

        if ([color isEqual:[UIColor colorWithRed:1 green:1 blue:1 alpha:1]]) {

            plate.backgroundColor = [UIColor whiteColor];

        } else {

            plate.backgroundColor = [UIColor grayColor];

        }

        [self flip:plate];

    }

    

    [UIView animateWithDuration:0.3 animations:^{

        self.iLabel.alpha = 0;

    }];

}

– (void)flip:(UIView*)v

{

    float delay = (arc4random() % 10) * 0.01;

    [UIView animateWithDuration:0.5 delay:delay options:UIViewAnimationOptionCurveLinear animations:^{

        v.layer.transform = CATransform3DRotate(v.layer.transform, M_PI/2.0, 0, 1, 0);

    } completion:^(BOOL finished) {

        

        if ([v.backgroundColor isEqual:[UIColor whiteColor]]) {

            v.backgroundColor = [UIColor grayColor];

        } else {

            v.backgroundColor = [UIColor whiteColor];

        }

        

        [UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationOptionCurveLinear animations:^{

            v.layer.transform = CATransform3DRotate(v.layer.transform, M_PI/2.0, 0, 1, 0);

        } completion:^(BOOL finished) {

            [self flip:v];

        }];

    }];

}

– (void)createI

{

    self.iLabel = [[UILabel alloc] initWithFrame:self.view.bounds];

    self.iLabel.text = @”i”;

    self.iLabel.textAlignment = NSTextAlignmentCenter;

    self.iLabel.font = [UIFont boldSystemFontOfSize:400];

    self.iLabel.textColor = [UIColor whiteColor];

    [self.view addSubview:self.iLabel];

}

– (UIView*)createPlate

{

    UIView *plate = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];

    plate.layer.cornerRadius = 10;

    [self.view addSubview:plate];

    return plate;

}

– (UIColor *)colorOfPoint:(CGPoint)point

{

    unsigned char pixel[4] = {0};

    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();

    CGContextRef context = CGBitmapContextCreate(pixel, 1, 1, 8, 4, colorSpace, kCGBitmapAlphaInfoMask & kCGImageAlphaPremultipliedLast);

    

    CGContextTranslateCTM(context, -point.x, -point.y);

    

    [self.iLabel.layer renderInContext:context];

    

    CGContextRelease(context);

    CGColorSpaceRelease(colorSpace);

    

    //NSLog(@”pixel: %d %d %d %d”, pixel[0], pixel[1], pixel[2], pixel[3]);

    

    UIColor *color = [UIColor colorWithRed:pixel[0]/255.0 green:pixel[1]/255.0 blue:pixel[2]/255.0 alpha:pixel[3]/255.0];

    

    return color;

}

– (void)didReceiveMemoryWarning

{

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}

@end