NSPopUpButtonCell子类动画以标准外观关闭

时间:2015-03-23 15:00:49

标签: objective-c macos cocoa osx-yosemite nspopupbuttoncell

我已经创建了一个NSPopUpButtonCell子类来自定义它的外观。

当从弹出窗口中选择其中一个菜单项时,它会使用OS X 10.10上的标准弹出窗口显示所选内容。

我想用我的自定义外观制作动画。

自定义PopUp

Customized PopUp

动画选择

Animating Selection

我的实施

- (void)drawBezelWithFrame:(NSRect)frame inView:(NSView *)controlView {

    [[NSGraphicsContext currentContext] saveGraphicsState];

    NSBezierPath *rectanglePath = [NSBezierPath bezierPathWithRoundedRect:frame xRadius:5.0 yRadius:5.0];
    [[NSColor colorWithWhite:0.7 alpha:1.0] setFill];
    [rectanglePath fill];

    float width = frame.size.width;
    float height = frame.size.height;

    NSBezierPath *path = [NSBezierPath bezierPath];

    [path moveToPoint:CGPointMake(width - 5, height/2 - 2)];
    [path lineToPoint:CGPointMake(width - 10, height/2 - 7)];
    [path lineToPoint:CGPointMake(width - 15, height/2 - 2)];


    [path moveToPoint:CGPointMake(width - 5, height/2 + 2)];
    [path lineToPoint:CGPointMake(width - 10, height/2 + 7)];
    [path lineToPoint:CGPointMake(width - 15, height/2 + 2)];

    [path setLineWidth:2.0];

    [[NSColor darkGrayColor] setStroke];
    [path stroke];

    [NSGraphicsContext restoreGraphicsState];
}

1 个答案:

答案 0 :(得分:1)

您必须在Interface Builder上关闭有边框属性。

如果实际关闭边界,则必须将其打开然后关闭。

更好的方法是使用 - (void)drawBorderAndBackgroundWithFrame:(NSRect)cellFrame inView:(NSView *)controlView