【发布时间】:2017-05-04 19:50:22
【问题描述】:
我想实现一个保持在屏幕底部的视图,并且可以像在 iOS 的 Uber 应用程序中那样通过平移手势进行扩展? Uber Home screen向下拖动视图会最小化
【问题讨论】:
-
你已经尝试了什么?请发布您正在进行的工作实施。
标签: ios swift uiviewanimation
我想实现一个保持在屏幕底部的视图,并且可以像在 iOS 的 Uber 应用程序中那样通过平移手势进行扩展? Uber Home screen向下拖动视图会最小化
【问题讨论】:
标签: ios swift uiviewanimation
很少有第三方库可以让您的工作变得轻松。这是其中之一。 LNPopUpController。
或者,如果您想自定义代码并编写: 取一个视图控制器并在其上添加一个 UIView。现在添加 Pan Gesture 以查看如下所示。
func handlePan(pan : UIPanGestureRecognizer) {
let velocity = pan.velocityInView(self.superview).y //; print("Velocity : \(velocity)")
var location = pan.locationInView(self.superview!) //; print("Location : \(location)")
var movement = self.frame
movement.origin.x = 0
movement.origin.y = movement.origin.y + (velocity * 0.05) //; print("Frame.y : \(movement.origin.y)")
if pan.state == .Ended{
print("Gesture Ended")
panGestureEnded()
}else if pan.state == .Began { print("Gesture Began")
let center = self.center
offset.y = location.y - center.y //; print("Offset.y : \(offset.y)")
}else{ print("Gesture else")
animator.removeBehavior(snap)
// Apply the initial offset.
location.x -= offset.x
location.y -= offset.y
//print("location.y : \(location.y)")
// Bound the item position inside the reference view.
location.x = self.superview!.frame.width / 2
// Apply the resulting item center.
snap = UISnapBehavior(item: self, snapToPoint: location)
animator.addBehavior(snap)
}
}
【讨论】:
panGestureEnded 方法在做什么?