0

UIKit Dynamics を含むカスタム Segue を備えたモーダル View Controller を提示したいと思います。

この投稿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];
}

悲しいことに、目的のコントローラーが間違った位置に表示され、衝突の直後に消えてしまいます。

次のスケッチのように、何らかの結果を達成したいと思います。

コントローラーが下から飛び出し、上に余裕を持ってスナップする必要があります。 上から 3/4 スペースとしましょう。

実際、私の UI は次のように動作しています。カスタム セグエを起動する「+」ボタンをタップすると、オレンジ色の NavigationBar のすぐ下にブラック ボックスが表示されます。スケッチのようにオレンジ色のボックスの下の境界線からはみ出ません。それはただ現れては消えていきます。

これを達成するには何を編集すればよいですか?

4

0 に答える 0