UIKit Dynamics Pop模态视图控制器

时间:2014-07-12 10:46:31

标签: ios objective-c uikit-dynamics

我想提供一个带有自定义Segue的模态View Controller,包括UIKit Dynamics。

在此帖https://stackoverflow.com/a/23039173/1016102中由rdelmar复制以下代码,并尝试根据我的需要对其进行修改。

    -(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];
}

可悲的是,我的目的地控制器出现在错误的位置,并在碰撞后直接消失。

我想在下面的草图中给出一些结果。

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

实际上我的用户界面就是这样的:我点按了" +"触发我的自定义segue的按钮,黑色框直接弹出橙色NavigationBar。它不会像素描中那样从橙色框的底部边框弹出。它只是出现并消失在顶部。

我应该编辑什么来实现这个目标?

0 个答案:

没有答案