参考网页:http://segmentfault.com/a/1190000002420095
写的真不错。赞
横向滑动的手势 *** 作则是这两行代码:
let panGestureRecognizer = UIPanGestureRecognizer(target: self,action: "handlePanGesture:")centerNavigationController.vIEw.addGestureRecognizer(panGestureRecognizer)
handlePanGesture
处理了滑动手势:
func handlePanGesture(recognizer: UIPanGestureRecognizer) { // 判断是否从左向右 let gestureIsDraggingFromleftToRight = (recognizer.veLocityInVIEw(vIEw).x > 0) switch(recognizer.state) { // 刚刚开始滑动 case .Began: // 如果刚刚开始滑动的时候还处于主页面,则根据左右方向加入侧面菜单 if (currentState == .BothCollapsed) { if (gestureIsDraggingFromleftToRight) { addleftPanelVIEwController() } else { addRightPanelVIEwController() } } // 如果是正在滑动,则偏移主视图的坐标实现跟随手指位置移动 case .Changed: recognizer.vIEw!.center.x = recognizer.vIEw!.center.x + recognizer.translationInVIEw(vIEw).x recognizer.setTranslation(CGPointZero,inVIEw: vIEw) // 如果滑动结束 case .Ended: // 判断该左还是该右 if (leftVIEwController != nil) { let hasMovedGreaterThanHalfway = recognizer.vIEw!.center.x > vIEw.bounds.size.wIDth animateleftPanel(shouldExpand: hasMovedGreaterThanHalfway) } else if (rightVIEwController != nil) { let hasMovedGreaterThanHalfway = recognizer.vIEw!.center.x < 0 animateRightPanel(shouldExpand: hasMovedGreaterThanHalfway) } default: break }}总结
以上是内存溢出为你收集整理的SWIFT 抽屉菜单全部内容,希望文章能够帮你解决SWIFT 抽屉菜单所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)