NSScrollView scrollToTop

后端 未结 4 1518
一向
一向 2021-02-14 16:55

Does anyone know the correct way to scroll the NSScrollView to the top? I was looking for an equivalent to the UIView\'s scrollToTop method.

This is what I have so far,

4条回答
  •  梦毁少年i
    2021-02-14 17:42

    Finally figured it out. Works like a charm!

    if ([self hasVerticalScroller]) {
        self.verticalScroller.floatValue = 0;
    }
    
    NSPoint newOrigin = NSMakePoint(0, NSMaxY(((NSView*)self.documentView).frame) - self.boundsHeight);
    [self.contentView scrollToPoint:newOrigin];
    

提交回复
热议问题