gpt4 book ai didi

objective-c - 防止用户手动滚动 NSScrollview?

转载 作者:搜寻专家 更新时间:2023-10-30 20:05:47 25 4
gpt4 key购买 nike

我正在使用 NSScrollview 以编程方式滚动。我隐藏了水平和垂直滚动条,但用户仍然可以使用鼠标滚轮滚动。我想阻止这种手动滚动。

这就是我做自动滚动的方式

- (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];
}

它工作得很好,但我想阻止用户手动滚动(我只想以编程方式滚动)。有什么办法可以做到这一点吗?

最佳答案

像这样尝试创建自定义 ScrollView 类,然后包含以下代码:-

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

关于objective-c - 防止用户手动滚动 NSScrollview?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19806088/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com