侧滑是App开发中非常常见的功能,目前大部分App都有实现这个功能.
简单介绍一下这个QQ侧滑的实现的步骤
添加拖拽手势
//添加拖拽手势
let pan:UIPanGestureRecognizer = UIPanGestureRecognizer(target: self, action: "didPanEvent:")
self.view.addGestureRecognizer(pan)
设置侧滑出来的view,view的宽高,则是滑出view的尺寸.
// 1. 获取手指拖拽的时候, 平移的值
let translation:CGPoint = recognizer.translationInView(recognizer.view)
// 2. 让当前控件做响应的平移
recognizer.view!.transform = CGAffineTransformTranslate(recognizer.view!.transform, translation.x, 0);
// ================
UIApplication.sharedApplication().delegate!.window!!.subviews.first?.transform.tx = (recognizer.view?.transform.tx)!/3
// 3. 每次平移手势识别完毕后, 让平移的值不要累加
recognizer.setTranslation(CGPointZero, inView: recognizer.view)
设置侧滑动画的时间.
if (recognizer.state == UIGestureRecognizerState.Ended){
UIView.animateWithDuration(0.2, animations: { () -> Void in
if (recognizer.view!.frame.origin.x > KSCREEN.width*0.5) {
recognizer.view!.transform = rightScopeTransform;
UIApplication.sharedApplication().delegate!.window!!.subviews.first?.transform.tx = (recognizer.view?.transform.tx)!/3
}else{
recognizer.view!.transform = CGAffineTransformIdentity;
UIApplication.sharedApplication().delegate!.window!!.subviews.first?.transform.tx = (recognizer.view?.transform.tx)!/3
}
})
仅仅添加了手势侧滑,部分功能还待于完善,本demo仅供个人学习
Swift之QQ.gif
网友评论