/
TrafficLightViewController.m
76 lines (58 loc) · 1.9 KB
/
TrafficLightViewController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//
// TrafficLightViewController.m
// TrafficLight
//
// Created by Eelco Lempsink on 16-09-11.
// Copyright 2011 Unsolicited Code. All rights reserved.
//
#import "TrafficLightViewController.h"
#import <QuartzCore/CoreAnimation.h>
@interface TrafficLightViewController ()
@property (nonatomic,retain) CALayer* backgroundLayer;
@end
@implementation TrafficLightViewController
@synthesize backgroundLayer = _backgroundLayer;
- (void)dealloc {
self.backgroundLayer = nil;
[super dealloc];
}
#pragma mark - View lifecycle
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor blackColor];
CALayer* backgroundLayer = [CALayer layer];
backgroundLayer.frame = CGRectInset(self.view.bounds, 100, 50);
backgroundLayer.backgroundColor = [[UIColor blackColor] CGColor];
backgroundLayer.borderColor = [[UIColor whiteColor] CGColor];
backgroundLayer.borderWidth = 25;
backgroundLayer.cornerRadius = backgroundLayer.frame.size.width / 2;
[self.view.layer addSublayer:backgroundLayer];
self.backgroundLayer = backgroundLayer;
[self.view addGestureRecognizer:
[[[UITapGestureRecognizer alloc]
initWithTarget:self action:@selector(tapped)]
autorelease]];
}
- (void)tapped {
self.backgroundLayer.frame = self.view.bounds;
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return YES;
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
@end