Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Slide Sidebar Menu IOS 8 Swift [closed]

Tags:

swift

ios8

Is there a way to implement Slide Sidebar Menu (Like Facebook app) in IOS Swift without any third party library? I look for solutions but I only founded this feature implemented in Objective-C.

like image 326
Naldo Lopes Avatar asked Jun 09 '14 14:06

Naldo Lopes


2 Answers

I believe you can start form UISplitViewController which was drastically updated in iOS8. Watch sessions View Controller Advancements in iOS8 and Building Adaptive Apps with UIKit for details. They provide code example from second session (but not form first one :/). At this point it feels natural for me to make this kind of UI based on split view controller in iOS8.

Update: It looks like not all API they talking about are landed yet. In current beta4 mentioned in video condensesBarsOnSwipe is not presented, for example.

like image 63
Ilya Belikin Avatar answered Nov 19 '22 14:11

Ilya Belikin


I think using Custom View Controller Transitions is a solid approach for making slideout menus:

  • You can customize the animation.
  • The transition is interactive, so you can drag to progress forward and backward. The transition always finishes or rolls back, and never gets stuck in-between states.
  • You use Pan Gestures and Screen Edge Pan Gestures to drive the interaction. This means you can place them strategically to minimize conflict with horizontally gestured content.
  • You don't have to resort to Container Views. This means your app architecture is flatter, and you can use protocol-delegate instead of NSNotifications.
  • There's only one ViewController active at a time. Snapshots are used to give the illusion that there's a second VC on the screen.

interactive slide out animated GIF

Custom View Controller Transitions are difficult to learn at first (they were for me, at least). I wrote a blog post on how to create an interactive slideout menu, and tried my best to make it as easy to understand as possible.

You can also jump straight into the code on GitHub.

At a very high level, this is how it works:

  1. You open the slideout menu as a modal.
  2. You create custom animations for the present and dismiss transitions using the UIViewControllerAnimatedTransitioning protocol. You use a snapshot to represent the main view controller during animations.
  3. You create Pan Gesture Recognizers to present/dismiss the modal interactively.
  4. You wire the Pan Gesture events to a UIPercentDrivenInteractiveTransition object to keep the transition in sync with the user's movements.
  5. The presenting controller adopts the UIViewControllerTransitioningDelegate protocol and wires up all the custom animations and interactive transitions.

I actually have a previous answer on this thread that uses a Scrollview / Container View. This approach is OK for a prototype, but runs into a lot of edge cases and bugs when making your app production ready. Spending every week responding to blog comments and fixing edge cases is what motivated me to write a second blog post on the subject.

like image 16
Robert Chen Avatar answered Nov 19 '22 14:11

Robert Chen