我已经谷歌搜索一段时间了解决方案。但没有得到我需要的任何东西。后来我发现了一个工作方式相同的库,但方式相反,库是LNPopupController
我的问题是如何在轻扫手势上使viewcontroller从上到下移动?我可以调整这个库来实现它吗?
答案 0 :(得分:0)
您希望根据所关联的项目实施UIPanGesture
而不是UISwipeGesture
。
UIPanGestureRecognizer *panGestureRecognizer = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(viewDragged:)];
[yourCustomView addGestureRecognizer:panGestureRecognizer];
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)];
}
}