私は NSScrollView を持っています。ユーザー mouseDown がいつ NSScroller にあるのか知りたいです。(mouseDown をオーバーライドするために) NSScroller をサブクラス化すると、NSScrollView の水平スクローラーが描画/表示されなくなります。NSScroller の drawRect をオーバーライドすると (そしてそのスーパービューを使用して描画を行うと)、予想される NSRect で呼び出されますが、何も描画されません。私は何が欠けていますか?
- 実際には、予想される HScroller 領域の右側に垂直スクローラー トラックの 15x15 セグメントがあるようです。たぶん、setFrameRotation などを指定する必要があるかもしれません... MyHScroller の drawRect で NSFillRect を呼び出すと、予想される rect が描画されます - 90 度回転すると、予想される HScroller 領域の左側に 15x15 しか塗りつぶされません。
これが私の NSScrollView 作成コードです:
MyHScroller *pMyHScroller = [[MyHScroller alloc] init];
MyScrollView *pMyScrollView = [[MyScrollView alloc] initWithFrame:nsrcFrame];
// pMyHScroller = nil; // With this line uncommented, the HScroller is drawn perfectly
if (pMyHScroller)
{
[pMyScrollView setHorizontalScroller:pMyHScroller];
}
[pMyScrollView setHasVerticalScroller: NO];
[pMyScrollView setHasHorizontalScroller: YES];
[pMyScrollView setAutohidesScrollers: NO];
[pMyScrollView setBorderType: NSBezelBorder];
[pMyScrollView setAutoresizingMask:0|NSViewMinYMargin];
[pMyScrollView setHorizontalLineScroll: 10];
[pMyScrollView setHorizontalPageScroll: 100];
[pMyScrollView setScrollsDynamically: YES];
NSScroller サブクラスは次のとおりです。
@interface MyHScroller : NSScroller
{
}
- (void)mouseDown:(NSEvent *)eventInfo;
- (void)drawRect:(NSRect)nsrcDirty;
@end
@implementation MyHScroller // NSScroller
- (void)mouseDown:(NSEvent *)eventInfo
{
[super mouseDown:eventInfo];
}
- (void)drawRect:(NSRect)nsrcDirty
{
// This fills the expected HScoller area with yellow
[[NSColor yellowColor] set];
NSRectFill(nsrcDirty);
// This verifies the ends of the rect are visible
{
[[NSColor cyanColor] set];
NSBezierPath* aPath = [NSBezierPath bezierPath];
[aPath moveToPoint:NSMakePoint(bounds.origin.x , bounds.origin.y )];
[aPath lineToPoint:NSMakePoint(bounds.origin.x+20.0, bounds.origin.y+bounds.size.height/2.0)];
[aPath lineToPoint:NSMakePoint(bounds.origin.x , bounds.origin.y+bounds.size.height )];
[aPath stroke];
}
{
[[NSColor cyanColor] set];
NSBezierPath* aPath = [NSBezierPath bezierPath];
[aPath moveToPoint:NSMakePoint(bounds.origin.x+bounds.size.width , bounds.origin.y )];
[aPath lineToPoint:NSMakePoint(bounds.origin.x+bounds.size.width-20.0, bounds.origin.y+bounds.size.height/2.0)];
[aPath lineToPoint:NSMakePoint(bounds.origin.x+bounds.size.width , bounds.origin.y+bounds.size.height )];
[aPath stroke];
}
// This draws what appears to be a 15x15 Vertical Scroller track segment
// over the right size of the yellow rect
[super drawRect:nsrcDirty];
}
@end
MyScrollView は、スクロール同期用に関数が追加された単なる NSScrollView オーバーライドです。