6

私は NSTableView を持っています。ユーザーがいつ下までスクロールしたかを知りたいので、アクションを実行できます。これについてどうすればよいかよくわかりませんか?

更新:テーブルの下部を計算する方法は次のとおりです。

-(void)tableViewDidScroll:(CPNotification) notification
{
    var scrollView = [notification object];
    var currentPosition = CGRectGetMaxY([scrollView visibleRect]);
    var tableViewHeight = [messagesTableView bounds].size.height - 100;

    //console.log("TableView Height: " + tableViewHeight);
    //console.log("Current Position: " + currentPosition);

    if (currentPosition > tableViewHeight - 100)
    {
       console.log("we're at the bottom!");
    }
}
4

2 に答える 2

16

テーブルの -enclosingScrollView の -contentView から NSViewBoundsDidChangeNotification のオブザーバー (KVO/Bindings の意味ではなく、NSNotificationCenter の意味) として自分自身を追加し、表示される四角形に基づいて必要に応じて反応することができます。

アップデート

これをどこかで実行します (おそらく -awakeFromNib):

// Configure the scroll view to send frame change notifications
id clipView = [[tableView enclosingScrollView] contentView];
[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(myBoundsChangeNotificationHandler:)
                                             name:NSViewBoundsDidChangeNotification
                                           object:clipView];

これを便利な場所に置いてください:

- (void)myBoundsChangeNotificationHandler:(NSNotification *)aNotification
{

if ([aNotification object] == [[tableView enclosingScrollView] contentView])
    [self doSomethingInterestingIfDocumentVisibleRectSatisfiesMe];

}

基本的に、スクロール ビューを調べて-documentVisibleRect、下の数ピクセルが表示されているかどうかを確認します。ビュー プログラミング ガイドで説明されている反転した座標系 (「反転したビュー」) を持つビューの可能性を考慮することを忘れないでください。

于 2011-02-10T16:52:23.047 に答える
0

あなたの更新について:いくつかの理由で、私は var currentPosition = CGRectGetMaxY([scrollView visibleRect]); を持っています。常に同じ値です。NSClipView 境界を使用する方が良いことがわかりました。

NSClipView *clipView = ...;
NSRect newClipBounds = [clipView bounds];
CGFloat currentPosition = newClipBounds.origin.y + newClipBounds.size.height;
于 2016-08-17T10:19:56.553 に答える