diff --git a/KDXCollectionView.podspec b/KDXCollectionView.podspec new file mode 100644 index 0000000..4424c23 --- /dev/null +++ b/KDXCollectionView.podspec @@ -0,0 +1,14 @@ +Pod::Spec.new do |s| +s.name = 'KDXCollectionView' +s.version = '0.1.3' +s.license = { :type => 'MIT', :file => 'LICENSE' } +s.summary = 'A better collection view for Mac.' +s.homepage = 'https://github.com/lembacon/KDXCollectionView' +s.author = { 'Chongyu Zhu' => 'lembacon@gmail.com' } +s.source = { :git => 'https://github.com/tsfischer/KDXCollectionView.git' } +s.source_files = 'src/*.{h,c,m}' +s.requires_arc = false + +s.osx.deployment_target = '10.6' +s.osx.framework = 'Cocoa' +end \ No newline at end of file diff --git a/src/KDXCollectionView.m b/src/KDXCollectionView.m index 8d4e222..d194585 100644 --- a/src/KDXCollectionView.m +++ b/src/KDXCollectionView.m @@ -114,6 +114,10 @@ - (void)_delegateUpdateDraggingItemsForDrag:(id )draggingInfo; @implementation KDXCollectionView +// TSF 7/19/2016 Work-around for a nasty bug where visibleCells array is not trustable during a reloadData. +// Ugly, but trying to minimize pod code changes. +static BOOL doingPreReloadData = false; + #pragma mark - Synthesizing Properties @synthesize dataSource = _dataSource; @@ -448,11 +452,13 @@ - (void)deselectAllItems - (void)_preReloadData { + doingPreReloadData = true; [_selectedIndexes removeAllIndexes]; _hoveringIndex = NSNotFound; _numberOfItems = [self _dataSourceNumberOfItems]; [self _updateFrame]; + doingPreReloadData = false; } - (void)_postReloadData @@ -659,6 +665,7 @@ - (void)_fixLayoutAfterMoving _flags.shouldAnimateCellFrameChanging = YES; [self _updateFramesOfCells]; + [self _addVisibleCells]; _flags.shouldAnimateCellFrameChanging = oldShouldAnimateCellFrameChanging; } @@ -754,6 +761,7 @@ - (void)_fixLayoutAfterInsertion [self _updateFrame]; [self _updateFramesOfCells]; [self _removeInvisibleCells]; + [self _addVisibleCells]; _flags.shouldAnimateCellFrameChanging = oldShouldAnimateCellFrameChanging; } @@ -964,7 +972,9 @@ - (void)drawRect:(NSRect)dirtyRect - (void)setFrame:(NSRect)frameRect { [super setFrame:frameRect]; - [self _layout]; + if (!doingPreReloadData) { + [self _layout]; + } if ([self inLiveResize]) { [self setNeedsDisplay:YES]; @@ -2080,11 +2090,13 @@ - (BOOL)acceptsFirstResponder - (NSView *)hitTest:(NSPoint)aPoint { - if (NSMouseInRect(aPoint, [self visibleRect], [self isFlipped])) { + NSView *hitView = [super hitTest:aPoint]; + + if (!hitView && NSMouseInRect(aPoint, [self visibleRect], [self isFlipped])) { return self; } - return nil; + return hitView; } - (void)_clearTrackingArea