从顶部到底部Swift呈现ViewController

时间:2016-07-04 11:26:23

标签: swift uigesturerecognizer viewcontroller presentmodalviewcontroller presentviewcontroller

我已经谷歌搜索一段时间了解决方案。但没有得到我需要的任何东西。后来我发现了一个工作方式相同的库,但方式相反,库是LNPopupController

我的问题是如何在轻扫手势上使viewcontroller从上到下移动?我可以调整这个库来实现它吗?

1 个答案:

答案 0 :(得分:0)

您希望根据所关联的项目实施UIPanGesture而不是UISwipeGesture

创建UIPanGestureRecognizer

UIPanGestureRecognizer *panGestureRecognizer = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(viewDragged:)];

[yourCustomView addGestureRecognizer:panGestureRecognizer];

然后实现" viewDragged:"方法

heightForTheDraggableRegionLeftInTheView是当用户尝试关闭youCustomView时,您希望在屏幕上保留多少视图的值。

- (void) viewDragged: (UIPanGestureRecognizer *) gestureRecognizer {
    CGRect viewFrame = gestureRecognizer.view.frame;
    CGPoint locationOfTouch = [gestureRecognizer locationInView:self.view];

    // Let the user's finger match with the bottom of the NotificationView
    [gestureRecognizer.view setFrame:CGRectMake(viewFrame.origin.x, locationOfTouch.y + draggableHeightOfTheNotificationView - viewFrame.size.height, viewFrame.size.width, viewFrame.size.height)];

    // If the yourCustomView is being dragged too high, make sure you leave a draggable area so that the user can drag it later
    if (locationOfTouch.y  >= self.view.frame.size.height - heightForTheDraggableRegionLeftInTheView) {
    [gestureRecognizer.view setFrame:CGRectMake(viewFrame.origin.x, 0, viewFrame.size.width, viewFrame.size.height)];
    }

    // If the NotificationView will go to far below the screen keep it resting at the bottom of the screen
    if (locationOfTouch.y <= draggableHeightOfTheNotificationView) {
    [gestureRecognizer.view setFrame:CGRectMake(viewFrame.origin.x, draggableHeightOfTheNotificationView * 2 - self.view.frame.size.height, viewFrame.size.width, viewFrame.size.height)];
    }
}