您好,欢迎光临本网站![请登录][注册会员]  
文件名称: swift编写简单的左右菜单栏
  所属分类: iOS
  开发工具:
  文件大小: 73kb
  下载次数: 0
  上传时间: 2015-03-09
  提 供 者: yeli****
 详细说明: swift编写简单的左右菜单栏 // // MenuViewController.swift // Menu // // Created by innovane on 14-6-23. // Copyright (c) 2014年 innovane. All rights reserved. // import UIKit let kICSDrawerControllerLeftViewInitialOffset : CGFloat = 60.0 let kICSDrawerControllerDrawerDepth : CGFloat = 200.0 enum ICSDrawerControllerState : Int { case MenuControllerStateOpening case MenuControllerStateClosing } class MenuViewController: UIViewController { //用户点击center var tapGestureRecognizer : UITapGestureRecognizer! // 用户拖动视图 var panGestureRecognizer : UIPanGestureRecognizer! // 用户touch的点位置 var panGestureStartLocation : CGPoint! // 左边控制器 var leftViewController : UIViewController! //中间控制器 var centerViewController : UIViewController! var drawerState : ICSDrawerControllerState! init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) { super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil) // Custom initialization } override func viewDidLoad() { super.viewDidLoad() self.drawerState = ICSDrawerControllerState.MenuControllerStateClosing; } override func viewDidAppear(animated: Bool) { super.viewDidAppear(animated) // 将左边控制器加入导航栏中。 if self.leftViewController != nil{ if (self.leftViewController.view.superview == nil){ self.addChildViewController(self.leftViewController) self.view.insertSubview(self.leftViewController.view, atIndex:0) } } if self.centerViewController != nil{ if (self.centerViewController.view.superview == nil){ self.addChildViewController(self.centerViewController) self.view.addSubview(self.centerViewController.view) } } // 添加用户拖动事件。 self.panGestureRecognizer = UIPanGestureRecognizer() self.panGestureRecognizer.addTarget(self,action:"panGestureRecognized:"); self.centerViewController.view.addGestureRecognizer(self.panGestureRecognizer) } // 用户拖动视图调用代理方法。 func panGestureRecognized(panGestureRecognizer:UIPanGestureRecognizer){ // 用户对视图操控的状态。 var state = panGestureRecognizer.state; var location = panGestureRecognizer.locationInView(self.view) var velocity = panGestureRecognizer.velocityInView(self.view) switch (state) { case UIGestureRecognizerState.Began: // 记录用户开始点击的位置 self.panGestureStartLocation = location; println("Began") break; case UIGestureRecognizerState.Changed: println("Changed") var c = self.centerViewController.view.frame if (panGestureRecognizer.translationInView(self.centerViewController.view).x > 0){ if (self.drawerState == ICSDrawerControllerState.MenuControllerStateClosing){ c.origin.x = location.x - self.panGestureStartLocation.x; } }else if (panGestureRecognizer.translationInView(self.centerViewController.view).x > -kICSDrawerControllerDrawerDepth){ if (self.drawerState == ICSDrawerControllerState.MenuControllerStateOpening){ c.origin.x = panGestureRecognizer.translationInView(self.centerViewController.view).x+kICSDrawerControllerDrawerDepth } } self.centerViewController.view.frame = c ; break; case UIGestureRecognizerState.Ended: var c = self.centerViewController.view.frame // 表示用户需要展开 if (location.x - self.panGestureStartLocation.x > kICSDrawerControllerLeftViewInitialOffset){ self.didOpen() }else{ if (c.origin.x < (kICSDrawerControllerDrawerDepth - 40)){ self.didClose() }else{ self.didOpen() } } break; default: break; } } // 移除点击事件,添加拖动事件 func tapGestureRecognized(tapGestureRecognizer : UITapGestureRecognizer){ self.didClose(); } // 菜单栏打开 func didOpen(){ var c = self.centerViewController.view.frame c.origin.x = kICSDrawerControllerDrawerDepth; UIView.animateWithDuration(0.7,delay:0,usingSpringWithDamping:0.5,initialSpringVelocity:1.0,options:UIViewAnimationOptions.AllowUserInteraction,animations:{ self.centerViewController.view.frame = c ; },completion: { (finished: Bool) -> Void in }) self.drawerState = ICSDrawerControllerState.MenuControllerStateOpening //增加点击事件 if (self.tapGestureRecognizer == nil){ self.tapGestureRecognizer = UITapGestureRecognizer() self.tapGestureRecognizer.addTarget(self,action:"tapGestureRecognized:"); } self.centerViewController.view.addGestureRecognizer(self.tapGestureRecognizer) } // 菜单关闭 func didClose(){ if (self.drawerState == ICSDrawerControllerState.MenuControllerStateOpening){ self.drawerState = ICSDrawerControllerState.MenuControllerStateClosing self.centerViewController.view.removeGestureRecognizer(self.tapGestureRecognizer) } var c = self.centerViewController.view.frame c.origin.x = 0 UIView.animateWithDuration(0.5,delay:0,usingSpringWithDamping:0.9,initialSpringVelocity:1.0,options:UIViewAnimationOptions.AllowUserInteraction,animations:{ self.centerViewController.view.frame = c ; },completion: { (finished: Bool) -> Void in }) } } ...展开收缩
(系统自动生成,下载前可以参看下载内容)

下载文件列表

相关说明

  • 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
  • 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度
  • 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
  • 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
  • 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
  • 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.
 相关搜索: swift
 输入关键字,在本站1000多万海量源码库中尽情搜索: