码迷,mamicode.com
首页 > 其他好文 > 详细

不用抽屉实现qq左侧拦展示功能(简单界面实现)

时间:2016-05-05 19:12:21      阅读:274      评论:0      收藏:0      [点我收藏+]

标签:

重点逻辑在于,实现动画过程给最上层的控制器添加一个view,来实现动画的返回功能。

class first: UIViewController {

    //动画按钮

    var aniBtn:UIButton?

    //三个测试控制器

    var three: Three?

    var four: Three?

    var two: Two?

    //覆盖的view

    private var rightCoverView: UIView!

    //动画参数

    var leftShowTransform: CGAffineTransform {

        get {

            return CGAffineTransformScale(CGAffineTransformMakeTranslation(SlideMaxOffset * 0.8, SlideMaxOffset * 0.8 * 0.2 ), 0.8, 0.8)

        }

    }

 

    var leftHideTransform: CGAffineTransform {

        get {

            return CGAffineTransformScale(CGAffineTransformMakeTranslation(SlideMinOffset * 0.8, 0), 1.00, 1.00)

        }

    }

 

    var SlideMaxOffset: CGFloat {

        get {

            return UIScreen.mainScreen().bounds.size.width * 0.7

        }

    }

 

    var SlideMinOffset: CGFloat {

        get {

            return UIScreen.mainScreen().bounds.size.width * 0.0

        }

    }

    

    

    override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {

        print("touch")

    }

    

    override func viewDidLoad() {

        super.viewDidLoad()

        self.view.backgroundColor = UIColor.blueColor()

        self.setupSubview()

    }

    

    func setupSubview() {

        two = Two()

        self.view.addSubview(two!.view)

        self.addChildViewController(two!)

        three = {

            let th = Three()

            return th

            }()

        self.view.addSubview(three!.view)

        self.addChildViewController(three!)

        //核心,实现动画的过程给最上面的控制器添加一个view,来实现动画的返回功能

        rightCoverView = {

            let view = UIButton(frame: CGRectMake(0, 0, UIScreen.mainScreen().bounds.size.width, UIScreen.mainScreen().bounds.size.height))

            let gesture = UITapGestureRecognizer(target: self, action: "hideLeft")

            view.userInteractionEnabled = true

            view.addGestureRecognizer(gesture)

            view.backgroundColor = UIColor.greenColor()

            return view

            } ()

        

        aniBtn = UIButton()

        self.view.addSubview(aniBtn!)

        aniBtn?.frame = CGRectMake(100, 100, 20, 20)

        aniBtn?.backgroundColor = UIColor.redColor()

        aniBtn?.userInteractionEnabled = true

        aniBtn?.addTarget(self, action: "aniBtnClick", forControlEvents: .TouchDown)

    }

    func aniBtnClick (){

        three!.view.addSubview(rightCoverView)

        UIView.animateWithDuration(0.45, delay: 0, usingSpringWithDamping: 1.0, initialSpringVelocity: 0.45, options: .BeginFromCurrentState, animations: { () -> Void in

            self.three?.view.transform = self.leftShowTransform

            

            }) { (complete) -> Void in

                print("回调成功")

        }

    }

    func hideLeft() {

        rightCoverView.removeFromSuperview()

        UIView.animateWithDuration(0.45, delay: 0, usingSpringWithDamping: 1.0, initialSpringVelocity: 0.45, options: .BeginFromCurrentState, animations: { () -> Void in

            self.three?.view.transform = self.leftHideTransform

            

            }) { (complete) -> Void in

                print("yes")

        }        

    }

}

不用抽屉实现qq左侧拦展示功能(简单界面实现)

标签:

原文地址:http://www.cnblogs.com/hazhede/p/5462614.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!