【发布时间】:2016-03-01 23:40:47
【问题描述】:
我想从中心向左或向右滑动一些 UIView,但在边缘之后我想让视图消失。滑动应该由握住手指的位置跟踪,并且在手指滑动视图到右侧或左侧后,视图应该飞到他滑到的一侧,但如果视图没有滑动,我希望他返回到他所在的位置。
我尝试在我的 UIView 上使用 UIPanGestureRecognizer
我的自定义 UIView 是 ArtistDetailsView
var panGestureRecognizer: UIPanGestureRecognizer!
panGestureRecognizer = UIPanGestureRecognizer(target: self, action: "handlePanFrom:")
self.artistDetailsView.addGestureRecognizer(panGestureRecognizer)
那是在 viewDidLoad() 函数中
func handlePanFrom(recognizer: UIPanGestureRecognizer) {
let translation: CGPoint = recognizer.translationInView(recognizer.view)
let velocity: CGPoint = recognizer.velocityInView(recognizer.view)
print(translation)
if recognizer.state == UIGestureRecognizerState.Began {
}
else if recognizer.state == UIGestureRecognizerState.Changed {
//track the movement
}
else if recognizer.state == UIGestureRecognizerState.Ended {
//animate to final position
}
}
关于我的自定义视图 视图包围了整个屏幕 这意味着我的自定义视图和 ViewController 的重量是相等的。 当视图向左滑动时,视图的右侧应该在 ViewController 的左侧之后并消失,当视图向右滑动时,左侧应该在 ViewController 的右侧之后并消失。
问题是我不知道在 UIPanGestureRecognizer 的每个状态下该做什么。
如果有人能帮助我,我会很高兴的!
【问题讨论】:
标签: ios iphone swift uiview uigesturerecognizer