@@ -151,28 +151,34 @@ - (void)updateAlongsideRotation {
151151#pragma mark - Private
152152
153153- (void )show : (BOOL )show visibleCellsAnimated : (BOOL )animated {
154- NSArray *visibleCells = [self visibleCells ];
154+ NSArray *visibleCellsIndexPahts = [self indexPathsForVisibleRows ];
155+ NSInteger firstVisibleRowIndex = [(NSIndexPath *)visibleCellsIndexPahts.firstObject row ];
156+ NSInteger lastVisibleRowIndex = [(NSIndexPath *)visibleCellsIndexPahts.lastObject row ];
155157
156- if (visibleCells .count == 0 || self.animatingIndex == visibleCells. count ) {
158+ if (visibleCellsIndexPahts .count == 0 || self.animatingIndex > lastVisibleRowIndex ) {
157159 self.animatingIndex = 0 ;
158160 [self setUserInteractionEnabled: YES ];
159161 [self reloadData ];
160162 self.animatingState = Stable;
161163 return ;
162164 }
163165
164- UITableViewCell<YALContextMenuCell> *visibleCell = [visibleCells objectAtIndex: self .animatingIndex];
166+ NSIndexPath *animatingIndexPath = [NSIndexPath indexPathForRow: self .animatingIndex inSection: 0 ];
167+ UITableViewCell<YALContextMenuCell> *visibleCell = (UITableViewCell<YALContextMenuCell> *)[self cellForRowAtIndexPath: animatingIndexPath];
165168 if (visibleCell) {
166169 [self prepareCellForShowAnimation: visibleCell];
167170 [visibleCell contentView ].hidden = NO ;
168- Direction direction = ([visibleCells indexOfObject: visibleCell] == 0 ) ? right : top;
171+ Direction direction = (self. animatingIndex == firstVisibleRowIndex ) ? right : top;
169172
170173 [self show: show cell: visibleCell animated: animated direction: direction clockwise: NO completion: ^(BOOL completed) {
171- if (completed) {
172- self.animatingIndex ++;
173- [self show: show visibleCellsAnimated: animated];
174- }
174+ // ignore flag 'completed', cause if user scroll out animating cell, it will be false and menu will be empty(
175+ self.animatingIndex ++;
176+ [self show: show visibleCellsAnimated: animated];
175177 }];
178+ } else {
179+ // user scroolled animatingCell, so animate from first visible again
180+ self.animatingIndex = firstVisibleRowIndex;
181+ [self show: show visibleCellsAnimated: animated];
176182 }
177183}
178184
0 commit comments