Skip to content

Commit

Permalink
Merge pull request #166 from NYTimes/cdz/165-gradient-flicker
Browse files Browse the repository at this point in the history
Fix gradient flickering of caption view on iOS 9
  • Loading branch information
cdzombak committed Mar 7, 2016
2 parents 2752f7d + cac4eed commit 65a5cfb
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 65a5cfb

Please sign in to comment.