Skip to content

Commit

Permalink
Fix gradient flickering of caption view on iOS 9
Browse files Browse the repository at this point in the history
This implements @cxa's fix from nytimes#165 on top of the large project restructuring from nytimes#164 .

I've reproduced the issue and verfied this fix on an iOS 9 device.
  • Loading branch information
cdzombak committed Mar 7, 2016
1 parent 2752f7d commit cac4eed
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions NYTPhotoViewer/NYTPhotoCaptionView.m
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,15 @@ - (void)didMoveToSuperview {
- (void)layoutSubviews {
[super layoutSubviews];

void (^updateGradientFrame)() = ^{
self.gradientLayer.frame = self.layer.bounds;
};

updateGradientFrame();

// On iOS 8.x, when this view is height-constrained, neither `self.bounds` nor `self.layer.bounds` reflects the new layout height immediately after `[super layoutSubviews]`. Both of those properties appear correct in the next runloop.
// This problem doesn't affect iOS 9 and there may be a better solution; PRs welcome.
dispatch_async(dispatch_get_main_queue(), ^{
self.gradientLayer.frame = self.layer.bounds;
});
dispatch_async(dispatch_get_main_queue(), updateGradientFrame);
}

- (CGSize)intrinsicContentSize {
Expand Down

0 comments on commit cac4eed

Please sign in to comment.