-
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
4 changed files
with
185 additions
and
5 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
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
20 changes: 20 additions & 0 deletions
20
AdvancedGraphics/AdvancedGraphics/ImplicitAnimationViewController.h
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,20 @@ | ||
// | ||
// ImplicitAnimationViewController.h | ||
// AdvancedGraphics | ||
// | ||
// Created by Ben Sandofsky on 8/7/15. | ||
// Copyright © 2015 Chroma Noir LLC. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
@interface ImplicitAnimationViewController : UIViewController | ||
@end | ||
|
||
@interface MyCustomView : UIView | ||
@property (nonatomic, assign) BOOL isGoing; | ||
@end | ||
|
||
@interface MyCustomLayer:CALayer | ||
@property (nonatomic, assign) BOOL isGoing; | ||
@end |
91 changes: 91 additions & 0 deletions
91
AdvancedGraphics/AdvancedGraphics/ImplicitAnimationViewController.m
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,91 @@ | ||
// | ||
// ImplicitAnimationViewController.m | ||
// AdvancedGraphics | ||
// | ||
// Created by Ben Sandofsky on 8/7/15. | ||
// Copyright © 2015 Chroma Noir LLC. All rights reserved. | ||
// | ||
|
||
#import "ImplicitAnimationViewController.h" | ||
#import <QuartzCore/QuartzCore.h> | ||
|
||
@interface ImplicitAnimationViewController () | ||
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *centerConstraint; | ||
@property (weak, nonatomic) IBOutlet MyCustomView *animatedView; | ||
|
||
@end | ||
|
||
@implementation ImplicitAnimationViewController | ||
- (IBAction)didTapGo:(UIBarButtonItem *)sender { | ||
self.centerConstraint.constant = 100; | ||
[UIView animateWithDuration:0.35 animations:^{ | ||
[self.view layoutIfNeeded]; | ||
self.animatedView.isGoing = true; | ||
}]; | ||
} | ||
|
||
- (void)viewWillAppear:(BOOL)animated | ||
{ | ||
[super viewWillAppear:animated]; | ||
self.centerConstraint.constant = -100; | ||
} | ||
|
||
- (void)viewWillDisappear:(BOOL)animated | ||
{ | ||
[super viewWillDisappear:animated]; | ||
} | ||
|
||
- (nullable id<CAAction>)actionForLayer:(CALayer *)layer forKey:(NSString *)event | ||
{ | ||
return nil; | ||
} | ||
|
||
@end | ||
|
||
@implementation MyCustomView | ||
|
||
+ (Class)layerClass { | ||
return [MyCustomLayer class]; | ||
} | ||
|
||
- (nullable id<CAAction>)actionForLayer:(CALayer *)layer forKey:(NSString *)event | ||
{ | ||
id action = [super actionForLayer:layer forKey:event]; | ||
NSLog(@"key: %@, Action: %@", event, action); | ||
return action; | ||
} | ||
|
||
- (void)setIsGoing:(BOOL)isGoing | ||
{ | ||
MyCustomLayer *l = (MyCustomLayer *)self.layer; | ||
l.isGoing = isGoing; | ||
} | ||
|
||
- (BOOL)isGoing | ||
{ | ||
return [(MyCustomLayer *)self.layer isGoing]; | ||
} | ||
|
||
@end | ||
|
||
@implementation MyCustomLayer | ||
- (id)init | ||
{ | ||
self = [super init]; | ||
if (self){ | ||
[self _updateColor]; | ||
} | ||
return self; | ||
} | ||
- (void)setIsGoing:(BOOL)isGoing | ||
{ | ||
_isGoing = isGoing; | ||
[self _updateColor]; | ||
} | ||
|
||
- (void)_updateColor | ||
{ | ||
self.backgroundColor = _isGoing ? [UIColor greenColor].CGColor : [UIColor redColor].CGColor; | ||
} | ||
|
||
@end |