Move the controller from the bottom using gestures

I have a question (Objective-C related).

I want to create a Slide-Bottom ViewController on top of the Root Map View Controller by clicking on the annotation.

1) After clicking on the annotation, it should slide from the bottom and show 10% of the height;
2) after a violent upward movement - it should show up to 100% if the user drags it up completely.

3) on a downward gesture, the user should be able to reduce his apparent height to 10% again.
4) on the MapView click at the bottom so the ViewController should hide.

I am including a visual diagram of the process implementation.

enter image description here

Any ideas are greatly appreciated!

+3


source to share


2 answers


check this demo

NHSlidingController



PanningViewController

+1


source


You can always try to write your own segue animation to transition between ViewControllers. Just create a custom UIStoryboardSegue and override its run method. Here's a snippet to start with:

@interface HorizontalSegue : UIStoryboardSegue

@property CGPoint originatingPoint;

@end


@implementation VerticalSegue

- (void)perform {
    UIViewController *sourceViewController = self.sourceViewController;
    UIViewController *destinationViewController = self.destinationViewController;

    NSArray* windowArray = [UIApplication sharedApplication].windows;
    if (windowArray.count > 0) {
        UIWindow* appWindow = [windowArray lastObject];
        [appWindow insertSubview:destinationViewController.view aboveSubview:sourceViewController.view];
    }
    else
        [sourceViewController.view addSubview:destinationViewController.view];

    // Store original centre point of the destination view
    CGPoint originalCenter = destinationViewController.view.center;

    // Set center to start point of the button
    destinationViewController.view.center = CGPointMake(self.originatingPoint.x, self.originatingPoint.y*3);

    [UIView animateWithDuration:0.25
                          delay:0.0
                        options:UIViewAnimationOptionCurveEaseInOut
                     animations:^{
                         destinationViewController.view.center = originalCenter;
                     }
                     completion:^(BOOL finished){
                         [sourceViewController presentViewController:destinationViewController animated:NO completion:NULL]; // present VC
                     }];
}

@end

      

With this, you can easily create custom animations. I'm not entirely sure if the part with adding the ViewController to the window is correct, but this is something you could try and check / fix.



Another way to animate segues is to use CATransition:

-(void)perform
{
    UIViewController *sourceViewController = (UIViewController*)[self sourceViewController];
    UIViewController *destinationController = (UIViewController*)[self destinationViewController];

    CATransition* transition = [CATransition animation];
    transition.duration = 0.25;
    transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    transition.type = kCATransitionMoveIn; //kCATransitionMoveIn; //, kCATransitionPush, kCATransitionReveal, kCATransitionFade
    transition.subtype = kCATransitionFromLeft; //kCATransitionFromLeft, kCATransitionFromRight, kCATransitionFromTop, kCATransitionFromBottom

    [destinationController.view.layer addAnimation:transition forKey:kCATransition];
    [sourceViewController presentViewController:destinationController animated:NO completion:nil];
}

      

0


source







All Articles