-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored to enable certain behavior in subclasses
- Loading branch information
1 parent
ac9702d
commit d1a0101
Showing
18 changed files
with
659 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// | ||
// MKParentalGate.h | ||
// | ||
// Copyright 2013 Michael F. Kamprath | ||
// [email protected] | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
typedef void (^MKParentalGateSuccessBlock)(void); | ||
typedef void (^MKParentalGateFailureBlock)(void); | ||
|
||
@interface MKParentalGate : NSObject | ||
|
||
+(void)displayGateWithCurrentViewController:(UIViewController*)inViewController successBlock:(MKParentalGateSuccessBlock)inSuccessBlock failureBlock:(MKParentalGateFailureBlock)inFailureBlock; | ||
|
||
@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,46 @@ | ||
// | ||
// MKParentalGate.h | ||
// | ||
// Copyright 2013 Michael F. Kamprath | ||
// [email protected] | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
#ifndef __has_feature | ||
#define __has_feature(x) 0 | ||
#endif | ||
#ifndef __has_extension | ||
#define __has_extension __has_feature // Compatibility with pre-3.0 compilers. | ||
#endif | ||
|
||
#if !(__has_feature(objc_arc) && __clang_major__ >= 3) | ||
#error "MKParentalGate is designed to be used with ARC. Please add '-fobjc-arc' to the compiler flags of MKParentalGate.m." | ||
#endif // __has_feature(objc_arc) | ||
|
||
#import "MKParentalGate.h" | ||
#import "MKParentalGateViewController.h" | ||
|
||
@implementation MKParentalGate | ||
|
||
+(void)displayGateWithCurrentViewController:(UIViewController*)inViewController successBlock:(MKParentalGateSuccessBlock)inSuccessBlock failureBlock:(MKParentalGateFailureBlock)inFailureBlock | ||
{ | ||
|
||
|
||
MKParentalGateViewController* gateVC = [[MKParentalGateViewController alloc] initWithStopIcon:[UIImage imageNamed:@"stop.png"] goIcon:nil successBlock:inSuccessBlock failureBlock:inFailureBlock]; | ||
|
||
[inViewController presentViewController:gateVC animated:YES completion:NULL]; | ||
|
||
} | ||
|
||
@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,13 @@ | ||
// | ||
// MKParentalGateTouchCancelView.h | ||
// iPhoneMK Sample App | ||
// | ||
// Created by Michael Kamprath on 10/20/13. | ||
// | ||
// | ||
|
||
#import "MKTouchTrackingView.h" | ||
|
||
@interface MKParentalGateTouchCancelView : MKTouchTrackingView | ||
|
||
@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,31 @@ | ||
// | ||
// MKParentalGateTouchCancelView.m | ||
// iPhoneMK Sample App | ||
// | ||
// Created by Michael Kamprath on 10/20/13. | ||
// | ||
// | ||
|
||
#import "MKParentalGateTouchCancelView.h" | ||
|
||
@implementation MKParentalGateTouchCancelView | ||
|
||
- (id)initWithFrame:(CGRect)frame | ||
{ | ||
self = [super initWithFrame:frame]; | ||
if (self) { | ||
// Initialization code | ||
} | ||
return self; | ||
} | ||
|
||
/* | ||
// Only override drawRect: if you perform custom drawing. | ||
// An empty implementation adversely affects performance during animation. | ||
- (void)drawRect:(CGRect)rect | ||
{ | ||
// Drawing code | ||
} | ||
*/ | ||
|
||
@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,29 @@ | ||
// | ||
// MKParentalGateTouchTargetView.h | ||
// iPhoneMK Sample App | ||
// | ||
// Created by Michael Kamprath on 10/19/13. | ||
// | ||
// | ||
|
||
#import "MKTouchTrackingAnimationView.h" | ||
|
||
@class MKParentalGateTouchTargetView; | ||
|
||
@protocol MKParentalGateTouchTargetDelegate <NSObject> | ||
|
||
@required | ||
-(void)handleTargetTouchDown:(MKParentalGateTouchTargetView*)inTargetView; | ||
-(void)handleTargetTouchUp:(MKParentalGateTouchTargetView*)inTargetView; | ||
|
||
@end | ||
|
||
@interface MKParentalGateTouchTargetView : MKTouchTrackingAnimationView | ||
|
||
- (id)initWithFrame:(CGRect)frame stopIcon:(UIImage*)inStopIcon goIcon:(UIImage*)inGoIcon delegate:(id<MKParentalGateTouchTargetDelegate>)inDelegate; | ||
|
||
-(void)startAnimation; | ||
-(void)pauseAnimation; | ||
-(void)resumeAnimation; | ||
|
||
@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,70 @@ | ||
// | ||
// MKParentalGateTouchTargetView.m | ||
// iPhoneMK Sample App | ||
// | ||
// Created by Michael Kamprath on 10/19/13. | ||
// | ||
// | ||
|
||
#import "MKParentalGateTouchTargetView.h" | ||
@interface MKParentalGateTouchTargetView () | ||
@property (strong,nonatomic) UIImage* goIcon; | ||
@property (strong,nonatomic) UIImage* stopIcon; | ||
@property (weak,nonatomic) id<MKParentalGateTouchTargetDelegate> delegate; | ||
@end | ||
|
||
@implementation MKParentalGateTouchTargetView | ||
|
||
- (id)initWithFrame:(CGRect)frame stopIcon:(UIImage*)inStopIcon goIcon:(UIImage*)inGoIcon delegate:(id<MKParentalGateTouchTargetDelegate>)inDelegate; | ||
{ | ||
self = [super initWithFrame:frame]; | ||
if (self) { | ||
self.goIcon = inGoIcon; | ||
self.stopIcon = inStopIcon; | ||
self.delegate = inDelegate; | ||
|
||
MKSoundCoordinatedAnimationLayer* aniLayer = [[MKSoundCoordinatedAnimationLayer alloc] init]; | ||
aniLayer.frame = CGRectMake(0, 0, frame.size.width, frame.size.height); | ||
|
||
self.animationLayer = aniLayer; | ||
} | ||
return self; | ||
} | ||
|
||
/* | ||
// Only override drawRect: if you perform custom drawing. | ||
// An empty implementation adversely affects performance during animation. | ||
- (void)drawRect:(CGRect)rect | ||
{ | ||
// Drawing code | ||
} | ||
*/ | ||
|
||
#pragma mark - Animation | ||
|
||
-(void)startAnimation { | ||
[self.animationLayer startAnimating]; | ||
} | ||
|
||
-(void)pauseAnimation { | ||
[self.animationLayer pauseAnimation]; | ||
} | ||
|
||
-(void)resumeAnimation { | ||
[self.animationLayer resumeAnimation]; | ||
} | ||
#pragma mark - Touch Tracking | ||
|
||
-(void)touchInViewBegan { | ||
[self.delegate handleTargetTouchDown:self]; | ||
} | ||
|
||
-(void)touchUpInView { | ||
[self.delegate handleTargetTouchUp:self]; | ||
} | ||
|
||
-(void)touchTrackedOutOfView { | ||
[self.delegate handleTargetTouchUp:self]; | ||
[self cancelTouchTracking]; | ||
} | ||
@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,16 @@ | ||
// | ||
// MKParentalGateViewController.h | ||
// iPhoneMK Sample App | ||
// | ||
// Created by Michael Kamprath on 10/19/13. | ||
// | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
#import "MKParentalGate.h" | ||
|
||
@interface MKParentalGateViewController : UIViewController | ||
|
||
- (id)initWithStopIcon:(UIImage*)inStopIcon goIcon:(UIImage*)inGoIcon successBlock:(MKParentalGateSuccessBlock)inSuccessBlock failureBlock:(MKParentalGateFailureBlock)inFailureBlock; | ||
|
||
@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,141 @@ | ||
// | ||
// MKParentalGateViewController.m | ||
// iPhoneMK Sample App | ||
// | ||
// Created by Michael Kamprath on 10/19/13. | ||
// | ||
// | ||
|
||
#ifndef __has_feature | ||
#define __has_feature(x) 0 | ||
#endif | ||
#ifndef __has_extension | ||
#define __has_extension __has_feature // Compatibility with pre-3.0 compilers. | ||
#endif | ||
|
||
#if !(__has_feature(objc_arc) && __clang_major__ >= 3) | ||
#error "MKParentalGate is designed to be used with ARC. Please add '-fobjc-arc' to the compiler flags of MKParentalGateViewController.m." | ||
#endif // __has_feature(objc_arc) | ||
|
||
#import "MKParentalGateViewController.h" | ||
#import "MKParentalGateTouchTargetView.h" | ||
|
||
@interface MKParentalGateViewController () <MKParentalGateTouchTargetDelegate> | ||
|
||
@property (weak,nonatomic) IBOutlet UIView* topObjectView; | ||
@property (weak,nonatomic) IBOutlet UIView* bottomObjectView; | ||
@property (weak,nonatomic) IBOutlet UILabel* titleLabel; | ||
@property (weak,nonatomic) IBOutlet UILabel* topExplanationLabel; | ||
@property (weak,nonatomic) IBOutlet UILabel* bottomExplanationLabel; | ||
@property (strong,nonatomic) MKParentalGateTouchTargetView* topTarget; | ||
@property (strong,nonatomic) MKParentalGateTouchTargetView* bottomTarget; | ||
@property (strong,nonatomic) UIImage* goIcon; | ||
@property (strong,nonatomic) UIImage* stopIcon; | ||
@property (strong,nonatomic) MKParentalGateSuccessBlock successBlock; | ||
@property (strong,nonatomic) MKParentalGateFailureBlock failureBlock; | ||
|
||
-(NSDictionary*)topTouchTargetAnimation; | ||
-(NSDictionary*)bottomTouchTargetAnimation; | ||
|
||
@end | ||
|
||
@implementation MKParentalGateViewController | ||
|
||
- (id)initWithStopIcon:(UIImage*)inStopIcon goIcon:(UIImage*)inGoIcon successBlock:(MKParentalGateSuccessBlock)inSuccessBlock failureBlock:(MKParentalGateFailureBlock)inFailureBlock | ||
{ | ||
self = [super initWithNibName:@"MKParentalGateViewController" bundle:nil]; | ||
if (self) { | ||
self.stopIcon = inStopIcon; | ||
self.goIcon = inGoIcon; | ||
self.successBlock = inSuccessBlock; | ||
self.failureBlock = inFailureBlock; | ||
|
||
if ([self respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)]) { | ||
[self setNeedsStatusBarAppearanceUpdate]; | ||
} | ||
else { | ||
self.wantsFullScreenLayout = YES; | ||
} | ||
} | ||
return self; | ||
} | ||
-(BOOL)prefersStatusBarHidden { | ||
return YES; | ||
} | ||
|
||
- (void)didReceiveMemoryWarning | ||
{ | ||
[super didReceiveMemoryWarning]; | ||
// Dispose of any resources that can be recreated. | ||
} | ||
|
||
-(void)viewDidAppear:(BOOL)animated { | ||
[self.topTarget startAnimation]; | ||
[self.bottomTarget startAnimation]; | ||
} | ||
|
||
- (void)viewDidLoad | ||
{ | ||
[super viewDidLoad]; | ||
// Do any additional setup after loading the view from its nib. | ||
|
||
self.topTarget = [[MKParentalGateTouchTargetView alloc] initWithFrame:CGRectMake(0, (self.topObjectView.bounds.size.height - self.stopIcon.size.height)/2.0, self.stopIcon.size.width, self.stopIcon.size.height) stopIcon:self.stopIcon goIcon:self.goIcon delegate:self]; | ||
self.topTarget.animationLayer.config = [self topTouchTargetAnimation]; | ||
[self.topObjectView addSubview:self.topTarget]; | ||
|
||
self.bottomTarget = [[MKParentalGateTouchTargetView alloc] initWithFrame:CGRectMake(self.bottomObjectView.bounds.size.width - self.stopIcon.size.width, (self.bottomObjectView.bounds.size.height - self.stopIcon.size.height)/2.0, self.stopIcon.size.width, self.stopIcon.size.height) stopIcon:self.stopIcon goIcon:self.goIcon delegate:self]; | ||
self.bottomTarget.animationLayer.config = [self bottomTouchTargetAnimation]; | ||
[self.bottomObjectView addSubview:self.bottomTarget]; | ||
} | ||
|
||
#pragma mark - Animations | ||
|
||
-(NSDictionary*)topTouchTargetAnimation { | ||
NSMutableDictionary* animationConfig = [NSMutableDictionary dictionaryWithCapacity:4]; | ||
|
||
if ( nil != self.stopIcon ) { | ||
[animationConfig setObject:@{@"stillImageObj":self.stopIcon} forKey:@"meta"]; | ||
[animationConfig setObject:@{@"deltaX":[NSNumber numberWithFloat:0.0]} forKey:[NSNumber numberWithFloat:0.0]]; | ||
[animationConfig setObject:@{@"deltaX":[NSNumber numberWithFloat:(self.topObjectView.bounds.size.width - self.stopIcon.size.width)]} forKey:[NSNumber numberWithFloat:5.0]]; | ||
[animationConfig setObject:@{@"deltaX":[NSNumber numberWithFloat:0.0],@"lastFrameDuration":[NSNumber numberWithFloat:0.0]} forKey:[NSNumber numberWithFloat:10.0]]; | ||
} | ||
return animationConfig; | ||
} | ||
|
||
-(NSDictionary*)bottomTouchTargetAnimation { | ||
NSMutableDictionary* animationConfig = [NSMutableDictionary dictionaryWithCapacity:4]; | ||
|
||
if ( nil != self.stopIcon ) { | ||
[animationConfig setObject:@{@"stillImageObj":self.stopIcon} forKey:@"meta"]; | ||
[animationConfig setObject:@{@"deltaX":[NSNumber numberWithFloat:0.0]} forKey:[NSNumber numberWithFloat:0.0]]; | ||
[animationConfig setObject:@{@"deltaX":[NSNumber numberWithFloat:-(self.topObjectView.bounds.size.width - self.stopIcon.size.width)]} forKey:[NSNumber numberWithFloat:5.0]]; | ||
[animationConfig setObject:@{@"deltaX":[NSNumber numberWithFloat:0.0],@"lastFrameDuration":[NSNumber numberWithFloat:0.0]} forKey:[NSNumber numberWithFloat:10.0]]; | ||
} | ||
return animationConfig; | ||
} | ||
|
||
#pragma mark - MKParentalGateTouchTargetDelegate | ||
|
||
-(void)handleTargetTouchDown:(MKParentalGateTouchTargetView*)inTargetView { | ||
if ( inTargetView == self.topTarget ) { | ||
[self.topTarget pauseAnimation]; | ||
self.topObjectView.backgroundColor = [UIColor greenColor]; | ||
} | ||
else if ( inTargetView == self.bottomTarget ) { | ||
[self.bottomTarget pauseAnimation]; | ||
self.bottomObjectView.backgroundColor = [UIColor greenColor]; | ||
} | ||
|
||
} | ||
-(void)handleTargetTouchUp:(MKParentalGateTouchTargetView*)inTargetView { | ||
if ( inTargetView == self.topTarget ) { | ||
[self.topTarget resumeAnimation]; | ||
self.topObjectView.backgroundColor = [UIColor whiteColor]; | ||
} | ||
else if ( inTargetView == self.bottomTarget ) { | ||
[self.bottomTarget resumeAnimation]; | ||
self.bottomObjectView.backgroundColor = [UIColor whiteColor]; | ||
} | ||
} | ||
|
||
@end |
Oops, something went wrong.