从上到下 Swift 呈现 ViewController
Posted
技术标签:
【中文标题】从上到下 Swift 呈现 ViewController【英文标题】:Presenting ViewController from Top to Bottom Swift 【发布时间】:2016-07-04 11:26:22 【问题描述】:我在谷歌上搜索了一段时间以寻求解决方案。但是没有得到我需要的东西。后来我找到了一个工作相同但以相反方式工作的库,这个库是LNPopupController
我的问题是如何让视图控制器在滑动手势上从上到下移动?我可以调整这个库来实现它吗?
【问题讨论】:
你当然可以调整它,因为它是开源的。随意分叉并实现它。应该没那么难。 【参考方案1】:您希望根据您链接的项目实施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)];
【讨论】:
以上是关于从上到下 Swift 呈现 ViewController的主要内容,如果未能解决你的问题,请参考以下文章