0

如何在这种方法中获得按钮的矩形?

在下面的方法中,这NSRect buttonRect = ???是我需要获取名为frame / rect的对象的地方。NSButtonCell_buttonCell

- (NSCellHitResult)hitTestForEvent:(NSEvent *)event
                            inRect:(NSRect)cellFrame
                            ofView:(NSView *)controlView {

    NSCellHitResult hitType = [super hitTestForEvent:event inRect:cellFrame ofView:controlView];

    NSPoint location = [event locationInWindow];
    location = [controlView convertPoint:location fromView:nil];

    NSRect buttonRect = ??? //_buttonCell.frame;

    if (NSMouseInRect(location, buttonRect, [controlView isFlipped])) {
        // We are only sent tracking messages for trackable areas.

        hitType |= NSCellHitTrackableArea;

        NSLog(@"hit ");
        [_buttonCell setState:NSControlStateValueOn];
    }
    return hitType;
}

_buttonCell 被绘制为:

- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView{

    int x = cellFrame.origin.x;
    int y = cellFrame.origin.y;

    NSRect buttonRect = NSMakeRect(x, y, 24, 24);
    NSRect imageRect = NSMakeRect(x+24, y, 24, 24);
    NSRect textRect = NSMakeRect(x+48, y, cellFrame.size.width-50, 24);

    [_buttonCell drawWithFrame:buttonRect inView:controlView];
    [_imageCell drawWithFrame:imageRect inView:controlView];
    [_textCell drawWithFrame:textRect inView:controlView];

}
4

0 回答 0