문제

I am using an NSScrollview to scroll programatically. I have hidden the horizental and vertical scrollers but the user is still able to scroll using the mouse wheel.I want to prevent thismanual scrolling.

This is how I am doing the automatic scrolling

- (IBAction)scrollToMidAnimated:(id)sender
{
    [NSAnimationContext beginGrouping];
    [[NSAnimationContext currentContext] setDuration:2.0];
    NSClipView* clipView = [self.scrollView contentView];
    NSPoint newOrigin = [clipView bounds].origin;
    newOrigin.y = [self.scrollView contentView].frame.size.height/2.0;
    [[clipView animator] setBoundsOrigin:newOrigin];
    [NSAnimationContext endGrouping];
}

It works perfectly but I want to prevent the user from manual scrolling(I only want to scroll programatically).Is there any way to do that?

도움이 되었습니까?

해결책 2

Finally got the solution.I subclassed NSScrollView and overrided its method scrollwheel and left it empty.

- (void)scrollWheel:(NSEvent *)theEvent
{
    // Do nothing
}

다른 팁

Try like this create custom scrollview class and then include below piece of code:-

    - (void)scrollWheel:(NSEvent *)theEvent
    {
    [[self nextResponder] scrollWheel:theEvent];
     }

if you did hide the scrollers and prevent user scrolling, are you sure you want NSScrollView at all in the first place? Just use NSClipView and animate just like you are doing. No need to subclass and override scrollWheel:. Its a little more cleaner and concise.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top