7
7
8
8
import UIKit
9
9
10
+ extension NSUserDefaults {
11
+
12
+ func colorForKey( key: String ) -> UIColor ? {
13
+ var color : UIColor ?
14
+ if let colorData = dataForKey ( key) {
15
+ color = NSKeyedUnarchiver . unarchiveObjectWithData ( colorData) as? UIColor
16
+ }
17
+ return color
18
+ }
19
+
20
+ func setColor( color: UIColor ? , forKey key: String ) {
21
+ var colorData : NSData ?
22
+ if let color = color {
23
+ colorData = NSKeyedArchiver . archivedDataWithRootObject ( color)
24
+ }
25
+ setObject ( colorData, forKey: key)
26
+ }
27
+
28
+ }
29
+
30
+ class StageCollectionViewCell : UICollectionViewCell {
31
+ @IBOutlet var stageNameLabel : UILabel !
32
+ }
33
+
10
34
class StageViewController : UICollectionViewController {
11
35
12
- var savedScrollPosition : CGPoint = CGPoint ( x: 0 , y: 0 )
36
+ var savedScrollPosition = CGPoint ( x: 0 , y: 0 )
37
+ let stagesArray = [ " BMO Harris Pavilion " , " Briggs & Stratton Big Backyard " , " Harley-Davidson Roadhouse " , " Johnson Controls World Sound Stage " , " Marcus Amphitheater " , " Miller Lite Oasis " , " U.S. Cellular Connection Stage " , " Uline Warehouse " ]
38
+ let colorsArray = [ UIColor ( red: 255.00 / 255.00 , green: 85.00 / 255.00 , blue: 55.00 / 255.00 , alpha: 1.0 ) , UIColor ( red: 255.00 / 255.00 , green: 103.00 / 255.00 , blue: 77.00 / 255.00 , alpha: 1.0 ) , UIColor ( red: 255.00 / 255.00 , green: 200.00 / 255.00 , blue: 5.00 / 255.00 , alpha: 1.0 ) , UIColor ( red: 255.00 / 255.00 , green: 217.00 / 255.00 , blue: 1.00 / 255.00 , alpha: 1.0 ) , UIColor ( red: 0.00 / 255.00 , green: 212.00 / 255.00 , blue: 251.00 / 255.00 , alpha: 1.0 ) , UIColor ( red: 0.00 / 255.00 , green: 189.00 / 255.00 , blue: 235.00 / 255.00 , alpha: 1.0 ) , UIColor ( red: 3.00 / 255.00 , green: 237.00 / 255.00 , blue: 152.00 / 255.00 , alpha: 1.0 ) , UIColor ( red: 0.00 / 255.00 , green: 251.00 / 255.00 , blue: 174.00 / 255.00 , alpha: 1.0 ) ]
13
39
14
40
override func viewDidLoad( ) {
15
41
super. viewDidLoad ( )
@@ -29,76 +55,77 @@ class StageViewController: UICollectionViewController {
29
55
}
30
56
31
57
override func collectionView( collectionView: UICollectionView , numberOfItemsInSection section: Int ) -> Int {
32
- return 8
58
+ return stagesArray. count
59
+ }
60
+
61
+ func collectionView( collectionView: UICollectionView , layout collectionViewLayout: UICollectionViewLayout , sizeForItemAtIndexPath indexPath: NSIndexPath ) -> CGSize {
62
+ let halfWidth = UIScreen . mainScreen ( ) . bounds. size. width / 2
63
+ return CGSize ( width: halfWidth, height: halfWidth)
33
64
}
34
65
35
66
override func collectionView( collectionView: UICollectionView , cellForItemAtIndexPath indexPath: NSIndexPath ) -> UICollectionViewCell {
36
- let cell = collectionView. dequeueReusableCellWithReuseIdentifier ( " stage " , forIndexPath: indexPath) as UICollectionViewCell
37
- let stageLabel = cell. viewWithTag ( 1 ) as! UILabel
38
- stageLabel. text = stageTupleAtIndex ( indexPath) . stageName
39
- cell. backgroundColor = stageTupleAtIndex ( indexPath) . color
40
- cell. addSubview ( stageLabel)
67
+ let cell = collectionView. dequeueReusableCellWithReuseIdentifier ( " stage " , forIndexPath: indexPath) as! StageCollectionViewCell
68
+ cell. backgroundColor = colorsArray [ indexPath. row]
69
+ cell. stageNameLabel. text = stagesArray [ indexPath. row]
41
70
return cell
42
71
}
43
72
44
73
override func collectionView( collectionView: UICollectionView , didSelectItemAtIndexPath indexPath: NSIndexPath ) {
45
- let rect = collectionView. cellForItemAtIndexPath ( indexPath) !. frame
74
+ let cell = collectionView. cellForItemAtIndexPath ( indexPath) as! StageCollectionViewCell
75
+ let rect = cell. frame
46
76
let animateView = UIView ( frame: CGRect ( x: rect. origin. x, y: rect. origin. y - collectionView. contentOffset. y, width: rect. size. width, height: rect. size. height) )
47
- animateView. backgroundColor = stageTupleAtIndex ( indexPath) . color
48
- let animateLabel = UILabel ( frame: CGRect ( x: 0.0 , y: 0.0 , width: 320 , height: 160 ) )
49
- animateLabel. text = stageTupleAtIndex ( indexPath) . stageName
50
- animateLabel. font = UIFont ( name: " Futura " , size: 19 )
51
- if ( animateLabel. text == " Johnson Controls World Sound Stage " ) {
52
- animateLabel. font = UIFont ( name: " Futura " , size: 16 )
53
- }
54
- animateLabel. textColor = UIColor . whiteColor ( )
55
- animateLabel. textAlignment = NSTextAlignment . Center
77
+ animateView. backgroundColor = colorsArray [ indexPath. row]
78
+
79
+ let animateLabel = configureAnimateLabelWithFrame ( cell. stageNameLabel. frame)
80
+ animateLabel. text = stagesArray [ indexPath. row]
56
81
animateView. addSubview ( animateLabel)
57
82
self . view. addSubview ( animateView)
58
-
83
+
59
84
UIView . animateWithDuration ( 0.5 , animations: {
60
85
animateView. frame = CGRect ( x: 0.0 , y: 0.0 , width: UIScreen . mainScreen ( ) . bounds. size. width, height: UIScreen . mainScreen ( ) . bounds. size. height)
61
- animateLabel . frame = CGRect ( x: 20 , y: 15 , width: 280 , height: 26 )
86
+ animateView . subviews [ 0 ] . frame = CGRect ( x: 0.0 , y: 5.0 , width: UIScreen . mainScreen ( ) . bounds . size . width , height: 45.0 )
62
87
} , completion: {
63
88
finished in
64
89
animateView. removeFromSuperview ( )
65
- let storyboard = UIStoryboard ( name: " Main " , bundle: nil )
66
- let dailyViewController = storyboard. instantiateViewControllerWithIdentifier ( " dvc " ) as! DailyViewController
67
- dailyViewController. backgroundImage = self . backgroundImage ( )
68
- dailyViewController. selectedIndex = indexPath
69
- dailyViewController. savedScrollPosition = collectionView. contentOffset
70
- let rect = collectionView. cellForItemAtIndexPath ( indexPath) !. frame
71
- dailyViewController. returnRectangle = CGRect ( x: rect. origin. x, y: rect. origin. y - collectionView. contentOffset. y, width: rect. size. width, height: rect. size. height)
72
- dailyViewController. stageName = animateLabel. text
73
- dailyViewController. stageColor = animateView. backgroundColor
74
- dailyViewController. complimentaryColor = self . complimentaryColor ( indexPath)
75
- self . navigationController!. pushViewController ( dailyViewController, animated: false )
90
+ self . dailyViewTransitionWithStageIndex ( indexPath)
76
91
} )
77
92
}
78
93
79
- func stageTupleAtIndex( index: NSIndexPath ) -> ( stageName: String , color: UIColor ) {
80
- let stage1 = ( " BMO Harris Pavilion " , UIColor ( red: 255.00 / 255.00 , green: 85.00 / 255.00 , blue: 55.00 / 255.00 , alpha: 1.0 ) )
81
- let stage2 = ( " Briggs & Stratton Big Backyard " , UIColor ( red: 255.00 / 255.00 , green: 103.00 / 255.00 , blue: 77.00 / 255.00 , alpha: 1.0 ) )
82
- let stage3 = ( " Harley-Davidson Roadhouse " , UIColor ( red: 255.00 / 255.00 , green: 200.00 / 255.00 , blue: 5.00 / 255.00 , alpha: 1.0 ) )
83
- let stage4 = ( " Johnson Controls World Sound Stage " , UIColor ( red: 255.00 / 255.00 , green: 217.00 / 255.00 , blue: 1.00 / 255.00 , alpha: 1.0 ) )
84
- let stage5 = ( " Marcus Amphitheater " , UIColor ( red: 0.00 / 255.00 , green: 212.00 / 255.00 , blue: 251.00 / 255.00 , alpha: 1.0 ) )
85
- let stage6 = ( " Miller Lite Oasis " , UIColor ( red: 0.00 / 255.00 , green: 189.00 / 255.00 , blue: 235.00 / 255.00 , alpha: 1.0 ) )
86
- let stage7 = ( " U.S. Cellular Connection Stage " , UIColor ( red: 3.00 / 255.00 , green: 237.00 / 255.00 , blue: 152.00 / 255.00 , alpha: 1.0 ) )
87
- let stage8 = ( " Uline Warehouse " , UIColor ( red: 0.00 / 255.00 , green: 251.00 / 255.00 , blue: 174.00 / 255.00 , alpha: 1.0 ) )
88
- let stageArray = [ stage1, stage2, stage3, stage4, stage5, stage6, stage7, stage8]
89
- return stageArray [ index. row]
94
+ func dailyViewTransitionWithStageIndex( index: NSIndexPath ) {
95
+ let storyboard = UIStoryboard ( name: " Main " , bundle: nil )
96
+ let dailyViewController = storyboard. instantiateViewControllerWithIdentifier ( " dvc " ) as! DailyViewController
97
+
98
+ dailyViewController. backgroundImage = self . backgroundImage ( )
99
+ dailyViewController. selectedIndex = index
100
+ dailyViewController. savedScrollPosition = collectionView!. contentOffset
101
+ dailyViewController. stageName = stagesArray [ index. row]
102
+ dailyViewController. stageColor = colorsArray [ index. row]
103
+
104
+ let rect = collectionView!. cellForItemAtIndexPath ( index) !. frame
105
+ dailyViewController. returnRectangle = CGRect ( x: rect. origin. x, y: rect. origin. y - collectionView!. contentOffset. y, width: rect. size. width, height: rect. size. height)
106
+ complimentaryColor ( index)
107
+ self . navigationController!. pushViewController ( dailyViewController, animated: false )
90
108
}
91
109
92
- func complimentaryColor( index: NSIndexPath ) -> UIColor {
110
+ func configureAnimateLabelWithFrame( frame: CGRect ) -> UILabel {
111
+ let animateLabel = UILabel ( frame: frame)
112
+ animateLabel. font = UIFont ( name: " Futura " , size: 19 )
113
+ animateLabel. textColor = UIColor . whiteColor ( )
114
+ animateLabel. textAlignment = NSTextAlignment . Center
115
+ return animateLabel
116
+ }
117
+
118
+ func complimentaryColor( index: NSIndexPath ) {
93
119
var i = 0
94
120
switch ( index. row) {
95
121
case 0 , 2 , 4 , 6 :
96
122
i = 1
97
123
default :
98
124
i = - 1
99
125
}
100
- let complimentaryIndex = NSIndexPath ( forRow: index. row+ i, inSection: index. section)
101
- return stageTupleAtIndex ( complimentaryIndex) . color
126
+
127
+ NSUserDefaults . standardUserDefaults ( ) . setColor ( colorsArray [ index. row+ i] , forKey: " complimentaryColor " )
128
+ NSUserDefaults . standardUserDefaults ( ) . synchronize ( )
102
129
}
103
130
104
131
func backgroundImage( ) -> UIImage {
@@ -114,4 +141,3 @@ class StageViewController: UICollectionViewController {
114
141
}
115
142
116
143
}
117
-
0 commit comments