Skip to content

Commit

Permalink
Improving behavior when using XIBs for cells (contentView can be decl…
Browse files Browse the repository at this point in the history
…ared in XIB, and cell is configured correctly when init'd with coder)
  • Loading branch information
kettch committed May 30, 2016
1 parent 38ec08a commit a462512
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion JNWCollectionView/JNWCollectionViewCell.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
/// Alternatively, a custom content view can be set for a flatter heirarchy. Note that
/// any custom content views will have autoresizing masks applied to them, and the view
/// will be layer-backed.
@property (nonatomic, strong) NSView *contentView;
@property (nonatomic, strong) IBOutlet NSView *contentView;

/// Sets the background image or background color on a dedicated background view that
/// is always beneath the content view.
Expand Down
17 changes: 17 additions & 0 deletions JNWCollectionView/JNWCollectionViewCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,23 @@ - (instancetype)initWithFrame:(NSRect)frameRect {
return self;
}

- (instancetype)initWithCoder:(NSCoder *)coder {
self = [super initWithCoder:coder];
if (self == nil) return nil;

self.wantsLayer = YES;
self.layerContentsRedrawPolicy = NSViewLayerContentsRedrawOnSetNeedsDisplay;

_backgroundView = [[JNWCollectionViewCellBackgroundView alloc] initWithFrame:self.bounds];
_backgroundView.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;

_crossfadeDuration = 0.25;

[self addSubview:_backgroundView positioned:NSWindowBelow relativeTo:nil];

return self;
}

- (void)prepareForReuse {
[self.backgroundView.layer removeAllAnimations];

Expand Down

0 comments on commit a462512

Please sign in to comment.