我想实现一个位于屏幕底部的视图,并且可以像iOS的Uber应用程序一样以锅手势扩展?Uber主屏幕向下拖动时,视图将是最小的
很少有第三方库可以使您的工作变得容易。这就是其中之一。lnPopupController。
否则,如果要自定义代码并编写:请拿一个视图控制器,然后在其顶部添加一个Uiview。现在添加锅手势以如下图。
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)
}
}