禁用在NSTableView中滚动 [英] Disable scrolling in NSTableView
本文介绍了禁用在NSTableView中滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有一种简单的方法可以禁用NSTableView的滚动.
Is there a simple way to disable scrolling of an NSTableView.
似乎没有任何财产
[myTableView enclosingScrollView]
或[[myTableView enclosingScrollView] contentView]
禁用它.
It seems there isn't any property on
[myTableView enclosingScrollView]
or [[myTableView enclosingScrollView] contentView]
to disable it.
推荐答案
这对我有用:子类NSScrollView,可通过以下方法设置和覆盖:
This works for me: subclass NSScrollView, setup and override via:
- (id)initWithFrame:(NSRect)frameRect; // in case you generate the scroll view manually
- (void)awakeFromNib; // in case you generate the scroll view via IB
- (void)hideScrollers; // programmatically hide the scrollers, so it works all the time
- (void)scrollWheel:(NSEvent *)theEvent; // disable scrolling
@interface MyScrollView : NSScrollView
@end
#import "MyScrollView.h"
@implementation MyScrollView
- (id)initWithFrame:(NSRect)frameRect
{
self = [super initWithFrame:frameRect];
if (self) {
[self hideScrollers];
}
return self;
}
- (void)awakeFromNib
{
[self hideScrollers];
}
- (void)hideScrollers
{
// Hide the scrollers. You may want to do this if you're syncing the scrolling
// this NSScrollView with another one.
[self setHasHorizontalScroller:NO];
[self setHasVerticalScroller:NO];
}
- (void)scrollWheel:(NSEvent *)theEvent
{
// Do nothing: disable scrolling altogether
}
@end
我希望这会有所帮助.
这篇关于禁用在NSTableView中滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文