Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I managed to find a very simple, elegant way to do this, that mimics the Facebook app functionality perfectly.</p> <p><strong>Here's my approach:</strong></p> <ul> <li>Create view with status bar frame</li> <li>Set view background color to black, opacity to 0</li> <li>Add view as subview to any root view <em>(you need a view that will cover both the center view and the menus, so that it won't be confined to any single view - a good option for this is the container view controller used by your menu controller implementation)</em></li> <li>Set view's opacity in your menu controller implementation's menu animation method</li> </ul> <p><strong>Here's my specific implementation, using <a href="https://github.com/mutualmobile/MMDrawerController" rel="noreferrer">MMDrawerController</a>:</strong> </p> <p>I subclassed MMDrawerController (I actually already had a subclass for using <a href="https://github.com/mutualmobile/MMDrawerController/issues/74" rel="noreferrer">MMDrawerController with storyboards</a>), and added this code to the class's <code>init</code> method:</p> <pre><code>// Setup view behind status bar for fading during menu drawer animations if (OSVersionIsAtLeastiOS7()) { self.statusBarView = [[UIView alloc] initWithFrame:[[UIApplication sharedApplication] statusBarFrame]]; [self.statusBarView setBackgroundColor:[UIColor blackColor]]; [self.statusBarView setAlpha:0.0]; [self.view addSubview:self.statusBarView]; } // Setup drawer animations __weak __typeof(&amp;*self) weakSelf = self; // Capture self weakly [self setDrawerVisualStateBlock:^(MMDrawerController *drawerController, MMDrawerSide drawerSide, CGFloat percentVisible) { MMDrawerControllerDrawerVisualStateBlock block; block = (drawerSide == MMDrawerSideLeft) ? [MMDrawerVisualState parallaxVisualStateBlockWithParallaxFactor:15.0] : nil; // Right side animation : Left side animation if(block){ block(drawerController, drawerSide, percentVisible); } [weakSelf.statusBarView setAlpha:percentVisible]; // THIS IS THE RELEVANT CODE }]; </code></pre> <p>I also added <code>self.statusBarView</code> as a private property.</p> <ul> <li><p>The first section of code creates a view, configures it, and adds it as a subview of the MMDrawerController subclass's view. The <code>OSVersionIsAtLeastiOS7()</code> method is a custom method that simplifies the check to see if the device is running iOS 7 (if it isn't, your custom view will show up below the status bar, which you don't want).</p></li> <li><p>The second section of code is MMDrawerController's <code>setDrawerVisualStateBlock</code> method, which sets the animations code to be performed when a menu is being opened and closed. The first few lines of code are boilerplate code that sets one of the prebuilt animations blocks to each menu (I wanted parallax on the left, but nothing on the right). The relevant code is the last line of the block: <code>[weakSelf.statusBarView setAlpha:percentVisible];</code>, which sets the status bar view's opacity to match the percentage that the menu is currently open. This allows for the smooth cross animation you see in the Facebook app. You'll also notice I've assigned <code>self</code> to a variable <code>weakSelf</code>, so as to avoid the "retain cycle" compiler warning.</p></li> </ul> <p>This is my specific approach using MMDrawerController and a subclass, which I did more for convenience because I already had the subclass in place, than because it is necessarily the best approach or the only way to do it. It could probably be implemented in several other ways, using MMDrawerController without a subclass, or using any other side-drawer menu implementation.</p> <p><strong>The ending result is a smooth fading to black animation behind the status bar, exactly as you see in the new Facebook app.</strong></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload