0

I'm designing a Slide Navigation Panel due to that tutorial.

Everything works fine. Now I want to go further and work on some UX issues. This is how my app look like now. But still I can manipulate MapView. My goal is to do two things:

1) Prevent all interaction with MapView, such as scaling and moving

2) Close navigation panel, while tapping on viewController with map.

enter image description here

The main file for controlling this two controlller is containerViewController. Here is the source code for it:

    import UIKit
import QuartzCore

enum SlideOutState {
    case BothCollapsed
    case LeftPanelExpanded
}

class ContainerViewController: UIViewController {

    var centerNavigationController: UINavigationController!
    var centerViewController: ViewController!

    var currentState: SlideOutState = .BothCollapsed {
        didSet {
            let shouldShowShadow = currentState != .BothCollapsed
            showShadowForCenterViewController(shouldShowShadow)
        }
    }

    var leftViewController: SidePanelViewController?

  override func viewDidLoad() {
    super.viewDidLoad()

    centerViewController = UIStoryboard.centerViewController()
    centerViewController.delegate = self

    // wrap the centerViewController in a navigation controller, so we can push views to it
    // and display bar button items in the navigation bar
    centerNavigationController = UINavigationController(rootViewController: centerViewController)
    view.addSubview(centerNavigationController.view)
    addChildViewController(centerNavigationController)

    centerNavigationController.didMoveToParentViewController(self)

  }

}

let centerPanelExpandedOffset: CGFloat = 60

extension ContainerViewController: CenterViewControllerDelegate {

    func toggleLeftPanel() {

        let notAlreadyExpanded = (currentState != .LeftPanelExpanded)

        if notAlreadyExpanded {
            addLeftPanelViewController()
        }

        animateLeftPanel(shouldExpand: notAlreadyExpanded)

    }



    func addLeftPanelViewController() {

        if (leftViewController == nil) {
            leftViewController = UIStoryboard.leftViewController()
            leftViewController!.categories = Category.allCats()

            addChildSidePanelController(leftViewController!)
        }

    }

    func addChildSidePanelController(sidePanelController: SidePanelViewController) {
        view.insertSubview(sidePanelController.view, atIndex: 0)

        addChildViewController(sidePanelController)
        sidePanelController.didMoveToParentViewController(self)
    }


    func animateLeftPanel(shouldExpand shouldExpand: Bool) {

        if (shouldExpand) {
            currentState = .LeftPanelExpanded

            animateCenterPanelXPosition(targetPosition: CGRectGetWidth(centerNavigationController.view.frame) - centerPanelExpandedOffset)
        } else {
            animateCenterPanelXPosition(targetPosition: 0) { finished in
                self.currentState = .BothCollapsed

                self.leftViewController!.view.removeFromSuperview()
                self.leftViewController = nil;
            }
        }

    }

    func animateCenterPanelXPosition(targetPosition targetPosition: CGFloat, completion: ((Bool) -> Void)! = nil) {
        UIView.animateWithDuration(0.5, delay: 0, usingSpringWithDamping: 0.8, initialSpringVelocity: 0, options: .CurveEaseInOut, animations: {
            self.centerNavigationController.view.frame.origin.x = targetPosition
            }, completion: completion)
    }

    func showShadowForCenterViewController(shouldShowShadow: Bool) {
        if (shouldShowShadow) {
            centerNavigationController.view.layer.shadowOpacity = 0.8
        } else {
            centerNavigationController.view.layer.shadowOpacity = 0.0
        }
    }

}


private extension UIStoryboard {
  class func mainStoryboard() -> UIStoryboard { return UIStoryboard(name: "Main", bundle: NSBundle.mainBundle()) }

  class func leftViewController() -> SidePanelViewController? {
    return mainStoryboard().instantiateViewControllerWithIdentifier("LeftViewController") as? SidePanelViewController
  }


  class func centerViewController() -> ViewController? {
    return mainStoryboard().instantiateViewControllerWithIdentifier("CenterViewController") as? ViewController
  }

}

My idea is to create variable that stands for active side panel and write a function, that will solve my issues:

I see something like that:

func blockCenterView() {

    let AlreadyExpanded = (currentState = .LeftPanelExpanded)

    if AlreadyExpanded {
        //no idea what to write here
    }
}

Am I right, or there exist other variants for solving that problem?

Mohith P
  • 585
  • 5
  • 14
Daniel Chepenko
  • 2,229
  • 7
  • 30
  • 56

2 Answers2

0

Add this code whereever you want to stop interaction with mapView

mapView.userInteractionEnabled = false

To enable it back,

mapView.userInteractionEnabled = true

Note : mapView is an instance of MKMapView

PS

SWRevealViewController

Source : Github

Step By Step Tutorial : More Flexible Slide View

This is what I was able to create using this awesome framework

enter image description here

App Link : AirMate on AppStore

aashish tamsya
  • 4,903
  • 3
  • 23
  • 34
0

Try to set the following properties to false

mapView.zoomEnabled = false
mapView.scrollEnabled = false
mapView.userInteraction = false

Also check the Interface Builder for the user Interactions:enter image description here

Rahul
  • 241
  • 1
  • 12