Использование left: calc(50% - Wpx/2);
, где W - ширина элемента, работает для меня.
Я нашел решение своей проблемы, что я доволен:
[_tableView insertRowsAtIndexes:indexSet withAnimation:NSTableViewAnimationEffectGap];
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
NSUInteger firstIndex = [indexSet firstIndex];
[_tableView scrollRowToVisible:firstIndex];
}];
Я просто задерживаю запрос прокрутки до следующего цикла цикла.
У нас были проблемы с этим, поэтому мы закончили выполнение прокрутки, как и другие анимации, чтобы сохранить строку на экране. Вы бы назвали этот код внутри вашей анимационной группы, где вы изменяете таблицу.
Код выглядит следующим образом:
- (BOOL)scrollRowToVisible:(NSInteger)row animate:(BOOL)animate;
{
LIClipView *const clipView = (id)_sourceListOutlineView.enclosingScrollView.contentView;
const NSRect finalFrameOfRow = [_sourceListOutlineView rectOfRow:row];
const NSRect clipViewBounds = clipView.bounds;
if (NSIsEmptyRect(finalFrameOfRow) || _sourceListOutlineView.numberOfRows <= 1)
return NO;
const NSRect finalFrameOfLastRow = [_sourceListOutlineView rectOfRow:(_sourceListOutlineView.numberOfRows - 1)];
if (NSMaxY(finalFrameOfLastRow) <= NSHeight(clipViewBounds))
// The source list is shrinking to fully fit in its clip view (though it might still be larger while animating); no scrolling is needed.
return NO;
if (NSMinY(finalFrameOfRow) < NSMinY(clipViewBounds)) {
// Scroll top of clipView up to top of row
[clipView scrollToPoint:(NSPoint){0, NSMinY(finalFrameOfRow)} animate:animate];
return YES;
}
if (NSMaxY(finalFrameOfRow) > NSMaxY(clipViewBounds)) {
// Scroll bottom of clipView down to bottom of source, but not such that the top goes off-screen (i.e. repeated calls won't keep scrolling if the row is higher than visibleRect)
[clipView scrollToPoint:(NSPoint){0, MIN(NSMinY(finalFrameOfRow), NSMaxY(finalFrameOfRow) - NSHeight(clipViewBounds))} animate:animate];
return YES;
}
return NO;
}