UIStatusBar as in Facebook new iOS7 application

我的梦境 提交于 2019-11-30 04:03:59

In iOS 7, your view controllers' view is full screen. So you could just put two views on top of each other at the top 22 px (status bar height) of the view. The bottom one black and the top one the same color as your navigation bar. When swiping to the SWRevealViewController, with one of the UIScrollView delegate methods you can calculate how far it is in percentages and apply that value to the opacity of the subview with your navigation bar's color.

I had another approach that worked like a charm too.

first int the SWRevealViewController.h at the SWRevealView class I create a View @property called underStatusBarView to be put at the status bar position.

then in the - (id)initWithFrame:(CGRect)frame controller:(SWRevealViewController*)controller method I instantiate the @property set its color to black and its alpha to 0.

- (id)initWithFrame:(CGRect)frame controller:(SWRevealViewController*)controller
{
    self = [super initWithFrame:frame];
    if ( self )
    {
        _c = controller;
        CGRect bounds = self.bounds;

        _frontView = [[UIView alloc] initWithFrame:bounds];
        _frontView.autoresizingMask =   UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;

        [self addSubview:_frontView];

        CALayer *frontViewLayer = _frontView.layer;
        frontViewLayer.masksToBounds = NO;
        frontViewLayer.shadowColor = [UIColor blackColor].CGColor;

        /* Here starts my under status bar implementation */
        CGRect statusFrame = [[UIApplication sharedApplication]statusBarFrame];
        _underStatusBarView = [[UIView alloc]initWithFrame:statusFrame];
        [_underStatusBarView setBackgroundColor:[UIColor blackColor]];
        [_underStatusBarView setAlpha:0.0];
        [self addSubview:_underStatusBarView];
        /* here it ends */

        //frontViewLayer.shadowOpacity = 1.0f;
        frontViewLayer.shadowOpacity = _c.frontViewShadowOpacity;
        frontViewLayer.shadowOffset = _c.frontViewShadowOffset;
        frontViewLayer.shadowRadius = _c.frontViewShadowRadius;
    }

    return self;
}

Then I added a single line of code to the private method responsible for laying out the rear views - (void)_layoutRearViewsForLocation:(CGFloat)xLocation to change the _underStatusBarView alpha according to the front view location.

- (void)_layoutRearViewsForLocation:(CGFloat)xLocation
{
    CGRect bounds = self.bounds;

    CGFloat rearRevealWidth = _c.rearViewRevealWidth;
    if ( rearRevealWidth < 0) rearRevealWidth = bounds.size.width + _c.rearViewRevealWidth;

    CGFloat rearXLocation = scaledValue(xLocation, -_c.rearViewRevealDisplacement, 0, 0, rearRevealWidth);

    CGFloat rearWidth = rearRevealWidth + _c.rearViewRevealOverdraw;
    _rearView.frame = CGRectMake(rearXLocation, 0.0, rearWidth, bounds.size.height);

    CGFloat rightRevealWidth = _c.rightViewRevealWidth;
    if ( rightRevealWidth < 0) rightRevealWidth = bounds.size.width + _c.rightViewRevealWidth;

    CGFloat rightXLocation = scaledValue(xLocation, 0, _c.rightViewRevealDisplacement, -rightRevealWidth, 0);

    CGFloat rightWidth = rightRevealWidth + _c.rightViewRevealOverdraw;
    _rightView.frame = CGRectMake(bounds.size.width-rightWidth+rightXLocation, 0.0f, rightWidth, bounds.size.height);

    /*this line changes the under status bar view alpha*/
   _underStatusBarView.alpha = xLocation/rearRevealWidth;
}

How you are using the rightRevealView you should change the rearRevealWidht to rightRevealWidth just to prevent future compatibility issues.

I really liked your approach. I've made a couple updates to your code and want to submit it to the project. If you have any issues with me doing so, please let me know.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!