Skip to content

Instantly share code, notes, and snippets.

@BradB132
BradB132 / TTViewController.m
Created June 10, 2015 05:01
ViewControllerTransitionsPart2-4
-(float)percentForPinch:(UIPinchGestureRecognizer*)pinch
{
return (pinch.scale - 1.0f)/2.0f;//denominator is just a fudge factor to get the 'feel' right
}
-(void)handlePinch:(UIPinchGestureRecognizer*)pinch
{
switch (pinch.state)
{
case UIGestureRecognizerStateBegan:
@BradB132
BradB132 / TTViewController.m
Last active August 29, 2015 14:22
ViewControllerTransitionsPart2-3
- (void)viewDidLoad
{
[super viewDidLoad];
self.pinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(handlePinch:)];
[self.view addGestureRecognizer:_pinch];
self.transition = [[UIPercentDrivenInteractiveTransition alloc] init];
self.navigationController.delegate = self;
@BradB132
BradB132 / TTViewController.m
Created June 10, 2015 04:57
ViewControllerTransitionsPart2-2
@property (nonatomic, strong) UIPercentDrivenInteractiveTransition* transition;
@property (nonatomic, strong) UIPinchGestureRecognizer* pinch;
@BradB132
BradB132 / TTPushAnimator.m
Created June 10, 2015 04:54
ViewControllerTransitionsPart2-1
- (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionContext
{
UIViewController* toController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
UIViewController* fromController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
UIView* container = [transitionContext containerView];
//get rects that represent the top and bottom halves of the screen
CGSize viewSize = fromController.view.bounds.size;
CGRect topFrame = CGRectMake(0, 0, viewSize.width, viewSize.height/2);
CGRect bottomFrame = CGRectMake(0, viewSize.height/2, viewSize.width, viewSize.height/2);
@BradB132
BradB132 / TTPushAnimator.m
Created June 10, 2015 04:51
ViewControllerTransitionsPart1-5
- (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionContext
{
UIViewController* toController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
UIViewController* fromController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
UIView* container = [transitionContext containerView];
//get rects that represent the top and bottom halves of the screen
CGSize viewSize = fromController.view.bounds.size;
CGRect topFrame = CGRectMake(0, 0, viewSize.width, viewSize.height/2);
CGRect bottomFrame = CGRectMake(0, viewSize.height/2, viewSize.width, viewSize.height/2);
@BradB132
BradB132 / TTViewController.m
Created June 10, 2015 04:50
ViewControllerTransitionsPart1-4
#pragma mark - UINavigationControllerDelegate
- (id <UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController
animationControllerForOperation:(UINavigationControllerOperation)operation
fromViewController:(UIViewController *)fromVC
toViewController:(UIViewController *)toVC
{
switch(operation)
{
case UINavigationControllerOperationPush:
@BradB132
BradB132 / TTFadeAnimator.m
Created June 10, 2015 04:48
ViewControllerTransitionsPart1-3
#define kTransitionDuration 0.35
// ...
#pragma mark - UIViewControllerAnimatedTransitioning
- (NSTimeInterval)transitionDuration:(id <UIViewControllerContextTransitioning>)transitionContext
{
return kTransitionDuration;
}
@BradB132
BradB132 / TTViewController.m
Created June 10, 2015 04:47
ViewControllerTransitionsPart1-2
#pragma mark - UINavigationControllerDelegate
- (id <UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController
animationControllerForOperation:(UINavigationControllerOperation)operation
fromViewController:(UIViewController *)fromVC
toViewController:(UIViewController *)toVC
{
return [[TTFadeAnimator alloc] init];
}
@BradB132
BradB132 / TTViewController.m
Last active August 29, 2015 14:22
ViewControllerTransitionsPart1-1
- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationController.delegate = self;
}
@BradB132
BradB132 / SwiftTricks.swift
Last active August 29, 2015 14:22
SwiftTricks-4
func application(application: UIApplication, _: [NSObject: AnyObject]?) -> Bool {
//we don't care about launch options
return true
}