2
votes

I'm trying for 2 hours now to get my scrollview to scroll a specific point. Its frustrating and I cant tell you why it wont work.

I have a scrollview and in it is a NSClipView. They are getting created in my AppDelegate right before my scrollPoint.

but either

[myclipview scrollPoint:NSMakePoint(1000.0, 0.0)];

works, neither

[[self.scrollView documentView] scrollPoint:NSMakePoint(1000.0, 0.0)];

(I want it to scroll all the way to the right,but not with any flip method or sth.)

Found this question Why is [[NSScrollView documentView] scrollPoint:] not working in loadView method?

And did not help me, I dont try it in the loadView method either. scrollView and myclipview arent nil either. Any tips for me? The scrollview works fine except it wont scroll to my position.

EDIT

just to be shure, i made this small test project:

NSScrollView* myscrollview = [[NSScrollView alloc] initWithFrame:NSMakeRect(0, 0, 200, 200)];
NSClipView* myclipview = [[NSClipView alloc] initWithFrame:NSMakeRect(0, 0, 500, 400)];
[myscrollview setHasVerticalScroller:YES];
[myscrollview setHasHorizontalScroller:YES];
[myscrollview setDocumentView:myclipview];

[[myscrollview documentView] scrollPoint:NSMakePoint(400, 300)];

[self.window.contentView addSubview:myscrollview];

and it doesnt scroll anywhere, i think i'm missing something here...?

1
just to be shure i made this small testproject:bennibeef
I think you need to set the frame for the documentView of NSScrollView instance especially the height.Valent Richie
@PatrickTescher There is no "setContentOffset" outside of iOS. The question is about "NSScrollView" not "UIScrollView"original_username

1 Answers

1
votes

The Small Test Project what you have needs to be changed in the following way. I have tried this and seems to be working. Do let me know if you still have any more issues.

Hope this will fix the issue : )

   NSScrollView* myscrollview = [[NSScrollView alloc] initWithFrame:NSMakeRect(10.0f, 100.0f, 200, 200)];
    NSClipView* myclipview = [[NSClipView alloc] initWithFrame:NSMakeRect(10.0f, 100.0f, 500, 400)];
    [myscrollview setHasVerticalScroller:YES];
    [myscrollview setHasHorizontalScroller:YES];
    [myscrollview setDocumentView:myclipview];

    [self.window.contentView addSubview:myscrollview];


    //******** Code Changes from here**********
    //This Calculation needs to be done 
    CGPoint newScrollOrigin=NSMakePoint(0.0,NSMaxY([[myscrollview documentView] frame])
                                -NSHeight([[myscrollview contentView] bounds]));

    //Increment/Decrement in x of newScrollOrigin will move the scroll position horizontally
    //Increment/Decrement in y of newScrollOrigin will move the scroll position vertically.

    //Incrementation of Values depends on your requirement.
    CGPoint setOrigin = CGPointMake(newScrollOrigin.x , newScrollOrigin.y - 120.0f);

    //Set the Scroll Point
    [[myscrollview contentView] scrollToPoint:setOrigin];