UIKit Dynamics Pop Modal View Controlelr

半城伤御伤魂 提交于 2019-12-08 11:58:55

问题


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.

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?

来源:https://stackoverflow.com/questions/24712143/uikit-dynamics-pop-modal-view-controlelr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!