Skip to content

Commit

Permalink
added properties for animation duration and if the 3d transform anima…
Browse files Browse the repository at this point in the history
…tion should be used
  • Loading branch information
kgn committed Nov 14, 2012
1 parent 3fbb80d commit 42d4a82
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
2 changes: 2 additions & 0 deletions Partial View Presentation/JLBPartialModal.h
Expand Up @@ -15,6 +15,8 @@

@property (nonatomic) BOOL showsShadow;
@property (nonatomic) BOOL tapToDismiss;
@property (nonatomic) BOOL shouldTransform;
@property (nonatomic) NSTimeInterval animationDuration;
@property (weak, nonatomic) id <JLBPartialModalDelegate> delegate;

+ (id)sharedInstance;
Expand Down
42 changes: 26 additions & 16 deletions Partial View Presentation/JLBPartialModal.m
Expand Up @@ -94,7 +94,6 @@ @interface JLBPartialModal ()

@implementation JLBPartialModal

#define JLB_PARTIAL_MODAL_ANIMATION_DURATION 0.4f
#define JLB_PARTIAL_MODAL_WINDOW_VERTICAL_OFFSET 48.0f

+ (id)sharedInstance
Expand All @@ -112,6 +111,8 @@ - (id)init
self = [super init];
if (self) {
self.tapToDismiss = YES;
self.shouldTransform = YES;
self.animationDuration = 0.4f;
}
return self;
}
Expand Down Expand Up @@ -141,21 +142,28 @@ - (void)presentViewController:(UIViewController *)viewControllerToPresent dismis
self.window.rootViewController = self.containerViewController;
[self.window makeKeyAndVisible];

[self.containerViewController showContentWithAnimationDuration:JLB_PARTIAL_MODAL_ANIMATION_DURATION completion:nil];
[self.containerViewController showContentWithAnimationDuration:self.animationDuration completion:nil];

__block BOOL hasCalledDelegate = NO;

for (UIWindow *window in [[UIApplication sharedApplication] windows]) {
if (window != self.window) {
[window.layer addAnimation:[self pullBackAnimation] forKey:@"pullBackAnimation"];
[UIView animateWithDuration:JLB_PARTIAL_MODAL_ANIMATION_DURATION animations:^{
window.center = CGPointMake(window.center.x, window.center.y - JLB_PARTIAL_MODAL_WINDOW_VERTICAL_OFFSET);
} completion:^(BOOL finished) {
if(self.shouldTransform){
[window.layer addAnimation:[self pullBackAnimation] forKey:@"pullBackAnimation"];
[UIView animateWithDuration:self.animationDuration animations:^{
window.center = CGPointMake(window.center.x, window.center.y - JLB_PARTIAL_MODAL_WINDOW_VERTICAL_OFFSET);
} completion:^(BOOL finished) {
if (!hasCalledDelegate) {
[self.delegate didPresentPartialModalView:self];
hasCalledDelegate = YES;
}
}];
}else{
if (!hasCalledDelegate) {
[self.delegate didPresentPartialModalView:self];
hasCalledDelegate = YES;
}
}];
}
}
}
});
Expand All @@ -180,16 +188,18 @@ - (void)dismissViewController

// If this isn't called on the main queue, the resulting animation and removal can have a multi-second delay.
dispatch_async(dispatch_get_main_queue(), ^{
for (UIWindow *window in [[UIApplication sharedApplication] windows]) {
if (window != self.window) {
[window.layer addAnimation:[self pushForwardAnimation] forKey:@"pushForwardAnimation"];
[UIView animateWithDuration:JLB_PARTIAL_MODAL_ANIMATION_DURATION animations:^{
window.center = CGPointMake(window.center.x, window.center.y + JLB_PARTIAL_MODAL_WINDOW_VERTICAL_OFFSET);
}];
if(self.shouldTransform){
for (UIWindow *window in [[UIApplication sharedApplication] windows]) {
if (window != self.window) {
[window.layer addAnimation:[self pushForwardAnimation] forKey:@"pushForwardAnimation"];
[UIView animateWithDuration:self.animationDuration animations:^{
window.center = CGPointMake(window.center.x, window.center.y + JLB_PARTIAL_MODAL_WINDOW_VERTICAL_OFFSET);
}];
}
}
}
[self.containerViewController hideContentWithAnimationDuration:JLB_PARTIAL_MODAL_ANIMATION_DURATION completion:^(BOOL finished) {

[self.containerViewController hideContentWithAnimationDuration:self.animationDuration completion:^(BOOL finished) {
[self.window resignKeyWindow];
[self.window removeFromSuperview];
self.window = nil;
Expand Down Expand Up @@ -217,7 +227,7 @@ - (void)dismissViewController
- (CAKeyframeAnimation *)windowAnimation
{
CAKeyframeAnimation *anim = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
anim.duration = JLB_PARTIAL_MODAL_ANIMATION_DURATION;
anim.duration = self.animationDuration;
anim.calculationMode = kCAAnimationCubic;
anim.removedOnCompletion = NO;
anim.fillMode = kCAFillModeForwards;
Expand Down

0 comments on commit 42d4a82

Please sign in to comment.