forked from bsfan/UIViewController-PushTransition
-
Notifications
You must be signed in to change notification settings - Fork 1
/
UIViewController+PushTransition.m
46 lines (37 loc) · 1.64 KB
/
UIViewController+PushTransition.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
//
// UIViewController+PushTransition.m
// Created by http://github.com/iosdeveloper
//
#import "UIViewController+PushTransition.h"
#import <QuartzCore/QuartzCore.h>
@implementation UIViewController (PushTransition)
- (void)pushViewController:(UIViewController *)viewControllerToPush {
[viewControllerToPush setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
CATransition *transition = [CATransition animation];
[transition setDuration:0.75];
[transition setType:kCATransitionPush];
[transition setSubtype:kCATransitionFromRight];
[self.view.superview.layer addAnimation:transition forKey:nil];
if ([self respondsToSelector:@selector(presentViewController:animated:completion:)]) {
[self presentViewController:viewControllerToPush animated:YES completion:NULL];
} else {
[self presentModalViewController:viewControllerToPush animated:YES];
}
}
- (void)dismissPushedViewController {
CATransition *transition = [CATransition animation];
[transition setDuration:0.75];
[transition setType:kCATransitionPush];
[transition setSubtype:kCATransitionFromLeft];
if ([self respondsToSelector:@selector(presentedViewController)]) {
[self.presentedViewController.view.superview.layer addAnimation:transition forKey:nil];
} else {
[self.modalViewController.view.superview.layer addAnimation:transition forKey:nil];
}
if ([self respondsToSelector:@selector(dismissViewControllerAnimated:completion:)]) {
[self dismissViewControllerAnimated:YES completion:NULL];
} else {
[self dismissModalViewControllerAnimated:YES];
}
}
@end