-->

iOS7 Status Bar like the native weather app

2020-07-18 03:17发布

问题:

Does anyone know how can I reproduce a similar effect from the native iOS7 weather app?

Basically, the status bar inherits the view's background underneath, but the content doesn't show up. Also, a 1 pixel line is drawn after the 20 pixels height of the status bar, only if some content is underlayed.

回答1:

The best thing is to make it through the clipSubview of the view. You put your content into the view and make constraints to left/right/bottom and height. Height on scroll view you check is the cell has minus position and at that time you start to change the height of content (clip) view to get desired effect.

This is a real app you can download and take a look from www.fancyinteractive.com. This functionality will be available soon as next update.

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
NSArray *visibleCells = [convertorsTableView visibleCells];

if (visibleCells.count) {
    for (CVConverterTableViewCell *cell in visibleCells) {
        CGFloat positionYInView = [convertorsTableView convertRect:cell.frame toView:self.view].origin.y;

        [self clipLayoutConstraint:cell.clipHeightLayoutConstraint withPosition:positionYInView defaultHeight:cell.frameHeight];

        [cell.converterLabel layoutIfNeeded];
        [cell.iconImageView layoutIfNeeded];
    }
}

[self checkStatusBarSeperator:scrollView.contentOffset.y];
}

- (void)clipLayoutConstraint:(NSLayoutConstraint *)constraint withPosition:(CGFloat)position defaultHeight:(CGFloat)defaultHeight {
if (position < 0) {
    constraint.constant = (defaultHeight - -position - 20 > 10) ? defaultHeight - -position - 20 : 10;
} else
    constraint.constant = defaultHeight;
}



回答2:

You can accomplish this by setting a mask to the table view's layer. You will not be able however to render the animations inside the cells, but you can do those yourself behind the table view, and track their movement with the table view's scrollview delegate methods.

Here is some informations on CALayer masks: http://evandavis.me/blog/2013/2/13/getting-creative-with-calayer-masks