0

I would like to present a modal View Controller with a custom Segue including UIKit Dynamics.

Copied the following code by rdelmar in this post https://stackoverflow.com/a/23039173/1016102 and tried to modify it for what i want.

    -(id)initWithIdentifier:(NSString *)identifier source:(UIViewController *)source destination:(UIViewController *)destination {

    if (self = [super initWithIdentifier:identifier source:source destination:destination]) {
        UIViewController *src  = self.sourceViewController;
        UIViewController *dest = self.destinationViewController;
        self.animator = [[UIDynamicAnimator alloc] initWithReferenceView:src.view];
        [src addChildViewController:dest];
        [dest didMoveToParentViewController:src];
        dest.view.frame = CGRectMake(0, 300, src.view.bounds.size.width, src.view.bounds.size.height);
        [src.view addSubview:dest.view];
    }
    return self;
}

-(void)perform {
    UIGravityBehavior* gravityBehavior = [[UIGravityBehavior alloc] initWithItems:@[[self.destinationViewController view]]];

    CGVector vector = CGVectorMake(0, -1);
    [gravityBehavior setGravityDirection:vector];

    UICollisionBehavior *collide = [[UICollisionBehavior alloc] initWithItems:@[[self.destinationViewController view]]];

    CGPoint left = CGPointMake(self.animator.referenceView.bounds.origin.x, self.animator.referenceView.bounds.origin.y + self.animator.referenceView.bounds.size.height);
    CGPoint right = CGPointMake(self.animator.referenceView.bounds.origin.x + self.animator.referenceView.bounds.size.width, self.animator.referenceView.bounds.origin.y + self.animator.referenceView.bounds.size.height);

    [collide addBoundaryWithIdentifier:@"top" fromPoint:left toPoint:right];

    [collide setCollisionDelegate:self.sourceViewController];

    [self.animator addBehavior:gravityBehavior];
    [self.animator addBehavior:collide];
}

Sadly my destination Controller appears on the wrong position and is disapperaing directly after the collision.

I would like to achive some result as in the following sketch.

The Controller should pop out of the bottom and should snap with a margin to top. let's say 3/4 space from top.

Actually my UI is acting like this: I tap the "+" button which fires my custom-segue and the the black box pops directly under the orange NavigationBar. it doesn't pop from the bottom border of the orange box like in the sketch. it just appears and disappers with popping over the top.

What should i edit to achive this?

Community
  • 1
  • 1
regetskcob
  • 1,172
  • 1
  • 13
  • 35
  • 1
    I can't tell what you're trying to show with that sketch. Where do you want the view to start, and where is it starting now with this code? Do you just want it to "fall" up from the bottom, and bounce to a stop? – rdelmar Jul 12 '14 at 15:35
  • @rdelmar I want the Black Box in my sketch popping up from bottom to a stop at 3/4 of the view height. The View with the grey NavigationBar is the destination ViewController. The two little arrows should "view" the "snap" animation. Actually the View starts directly under my orange navigation bar and pops out of my view. – regetskcob Jul 12 '14 at 15:55
  • 1
    Still not sure I understand what "Actually the View starts directly under my orange navigation bar and pops out of my view" means? You use "View" twice in that sentence, and I don't know which views you mean. Is that map view fixed in its position? You want the black box at the bottom to fall up and bounce against the bottom of the map view? – rdelmar Jul 12 '14 at 16:03
  • Okay wait... I'll update the sketch a bit. Hope this is better to understand. The sketch is new and a bit more detailed description. – regetskcob Jul 12 '14 at 16:15
  • 1
    I think I understand now. One problem is your definition of "left" and "right". You changed the name to "top" but you didn't change the code -- those points still describe the bottom of the source view, not the bottom of the map view. Also, why are you starting the destination view at y= 300, and not y = bottom of the screen? Do you want it to start part way on the screen? – rdelmar Jul 12 '14 at 16:21
  • You're right. This was the problem... Thank you very much! :-) – regetskcob Jul 12 '14 at 16:24

0 Answers0