UIKitdynamicstream行音乐Modal View Controlelr

我想用包含UIKit Dynamics的自定义Segue来呈现模式化的视图控制器。

复制下面的代码rdelmar在这个posthttps://stackoverflow.com/a/23039173/1016102,并试图修改它为我想要的。

-(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空间。

其实我的用户界面是这样的:我点击“+”button,触发我的自定义赛格,黑色的盒子直接popup橙色NavigationBar下。 它不会像草图中那样从橙色框的下边缘popup。 它只是出现在顶部popup消散。

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