tar*_*mes 5 macos cocoa core-animation nstableview
将新行添加到 NSTableView 后,我想滚动到它。
当该行被添加到表的末尾时,滚动仅滚动到之前是最后一行的行。我最初以为我必须等待动画完成,但这并没有解决我的问题。这是我的代码:
[NSAnimationContext beginGrouping];
[_tableView insertRowsAtIndexes:indexSet withAnimation:NSTableViewAnimationEffectGap];
[[NSAnimationContext currentContext] setCompletionHandler:^{
// Scroll to the first inserted row
NSUInteger firstIndex = [indexSet firstIndex];
[_tableView scrollRowToVisible:firstIndex];
}];
[NSAnimationContext endGrouping];
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?
我找到了一个令我满意的解决方案:
[_tableView insertRowsAtIndexes:indexSet withAnimation:NSTableViewAnimationEffectGap];
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
NSUInteger firstIndex = [indexSet firstIndex];
[_tableView scrollRowToVisible:firstIndex];
}];
Run Code Online (Sandbox Code Playgroud)
我只是将滚动请求延迟到下一个运行循环。
| 归档时间: |
|
| 查看次数: |
1676 次 |
| 最近记录: |