-
Notifications
You must be signed in to change notification settings - Fork 472
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
152 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
AdvancedGraphics/AdvancedGraphics/Assets.xcassets/snowflake.imageset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"idiom" : "universal", | ||
"scale" : "1x" | ||
}, | ||
{ | ||
"idiom" : "universal", | ||
"filename" : "snowflake.png", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"idiom" : "universal", | ||
"scale" : "3x" | ||
} | ||
], | ||
"info" : { | ||
"version" : 1, | ||
"author" : "xcode" | ||
} | ||
} |
Binary file added
BIN
+4.02 KB
AdvancedGraphics/AdvancedGraphics/Assets.xcassets/snowflake.imageset/snowflake.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// | ||
// SnowViewController.h | ||
// AdvancedGraphics | ||
// | ||
// Created by Benjamin Sandofsky on 8/7/15. | ||
// Copyright © 2015 Chroma Noir LLC. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
@interface SnowViewController : UIViewController | ||
|
||
@end | ||
|
||
@interface SnowLayer : CALayer | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// | ||
// SnowViewController.m | ||
// AdvancedGraphics | ||
// | ||
// Created by Benjamin Sandofsky on 8/7/15. | ||
// Copyright © 2015 Chroma Noir LLC. All rights reserved. | ||
// | ||
|
||
#import "SnowViewController.h" | ||
|
||
#define SNOW_COUNT 20 | ||
|
||
@interface SnowViewController () | ||
@property (nonatomic, strong) NSMutableArray<SnowLayer *> *snowQueue; | ||
@end | ||
|
||
@implementation SnowViewController | ||
|
||
- (void)viewDidLoad | ||
{ | ||
[super viewDidLoad]; | ||
NSMutableArray<SnowLayer *> *array = [NSMutableArray array]; | ||
UIImage *snowFlakeImage = [UIImage imageNamed:@"snowflake"]; | ||
for (int i = 0; i < SNOW_COUNT; i++){ | ||
SnowLayer *snow = [[SnowLayer alloc] init]; | ||
snow.contents = (id)snowFlakeImage.CGImage; | ||
snow.frame = CGRectMake(0, -40, 40, 40); | ||
[self.view.layer addSublayer:snow]; | ||
[array addObject:snow]; | ||
} | ||
self.snowQueue = array; | ||
} | ||
|
||
- (IBAction)didTapStart:(UIBarButtonItem *)sender { | ||
[CATransaction begin]; | ||
[CATransaction setAnimationDuration:2.0]; | ||
CGFloat offset = 0.0; | ||
for (SnowLayer *snow in self.snowQueue) { | ||
CABasicAnimation *animation = [CABasicAnimation animation]; | ||
CGFloat x = (CGFloat)arc4random() / (CGFloat)UINT32_MAX * self.view.layer.bounds.size.width; | ||
CGPoint p = CGPointMake(x, -20.0); | ||
animation.fromValue = [NSValue valueWithCGPoint:p]; | ||
animation.keyPath = @"position"; | ||
p.y = self.view.frame.size.height + 20.0; | ||
animation.toValue = [NSValue valueWithCGPoint:p]; | ||
CGFloat randomOffset = (CGFloat)arc4random() / (CGFloat)UINT32_MAX; | ||
offset += 0.5 + randomOffset / 2.0; | ||
animation.beginTime = CACurrentMediaTime() + offset; | ||
animation.repeatCount = 1000; | ||
[snow addAnimation:animation forKey:@"snowFall"]; | ||
NSLog(@"Snowed: %f", x); | ||
} | ||
|
||
[CATransaction commit]; | ||
} | ||
|
||
@end | ||
|
||
@implementation SnowLayer | ||
|
||
@end |