You are on page 1of 4

Men Interactivo Swift

#import "SWRevealViewController.h"

if self.revealViewController() != nil {
menuButton.target = self.revealViewController()
menuButton.action = "revealToggle:"
self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
}

self.revealViewController().rearViewRevealWidth = 62
---------------------------------------------------------------------------------------------------------------------

import UIKit

// update our class definition to include `UIViewControllerInteractiveTransitioning` as one of


the protocols that this object adheres to
class MenuTransitionManager: NSObject, UIViewControllerAnimatedTransitioning,
UIViewControllerTransitioningDelegate, UIViewControllerInteractiveTransitioning {

private var interactive = false

// rest of class definition excluded...


}

func interactionControllerForPresentation(animator:
UIViewControllerAnimatedTransitioning) -> UIViewControllerInteractiveTransitioning? {
// if our interactive flag is true, return the transition manager object
// otherwise return nil
return self.interactive ? self : nil
}

func interactionControllerForDismissal(animator: UIViewControllerAnimatedTransitioning)


-> UIViewControllerInteractiveTransitioning? {
return self.interactive ? self : nil
}
import UIKit

class MainViewController: UITableViewController {

// create the transition manager object


var transitionManager = MenuTransitionManager()

override func viewDidLoad() {


super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {

let menu = segue.destinationViewController as MenuViewController


menu.transitioningDelegate = self.transitionManager

@IBAction func unwindToMainViewController (sender: UIStoryboardSegue){


// bug? exit segue doesn't dismiss so we do it manually...
self.dismissViewControllerAnimated(true, completion: nil)

override func didReceiveMemoryWarning() {


super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

/* MenuTransitionManager */

// private so can only be referenced within this object


private var enterPanGesture: UIScreenEdgePanGestureRecognizer!

// not private, so can also be used from other objects :)


var sourceViewController: UIViewController!
Now jump back to the main view controller class and use the new sourceViewController to
create a reference to this view controller.

/* MainViewController */

override func viewDidLoad() {


super.viewDidLoad()

// now we'll have a handy reference to this view controller


// from within our transition manager object
self.transitionManager.sourceViewController = self
}

private var enterPanGesture: UIScreenEdgePanGestureRecognizer!

var sourceViewController: UIViewController! {


didSet {
self.enterPanGesture = UIScreenEdgePanGestureRecognizer()
self.enterPanGesture.addTarget(self, action:"handleOnstagePan:")
self.enterPanGesture.edges = UIRectEdge.Left
self.sourceViewController.view.addGestureRecognizer(self.enterPanGesture)
}
}

// TODO: We need to complete this method to do something useful


func handleOnstagePan(pan: UIPanGestureRecognizer){
println("Todo: handle onstage gesture...")
}

func handleOnstagePan(pan: UIPanGestureRecognizer){

// how much distance have we panned in reference to the parent view?


let translation = pan.translationInView(pan.view!)

// do some math to translate this to a percentage based value


let d = translation.x / CGRectGetWidth(pan.view!.bounds) * 0.5

// now lets deal with different states that the gesture recognizer sends
switch (pan.state) {

case UIGestureRecognizerState.Began:
// set our interactive flag to true
self.interactive = true

// trigger the start of the transition


self.sourceViewController.performSegueWithIdentifier("presentMenu", sender: self)
break

case UIGestureRecognizerState.Changed:

// update progress of the transition


self.updateInteractiveTransition(d)
break

default: // .Ended, .Cancelled, .Failed ...

// return flag to false and finish the transition


self.interactive = false
self.finishInteractiveTransition()
}
}

// tell our transitionContext object that we've finished animating


if(transitionContext.transitionWasCancelled()){

transitionContext.completeTransition(false)
// bug: we have to manually add our 'to view' back http://openradar.appspot.com/radar?
id=5320103646199808
UIApplication.sharedApplication().keyWindow?.addSubview(screens.from.view)

}
else {

transitionContext.completeTransition(true)
// bug: we have to manually add our 'to view' back http://openradar.appspot.com/radar?
id=5320103646199808
UIApplication.sharedApplication().keyWindow?.addSubview(screens.to.view)

You might also like