检查NSButton是否在drawRect上关闭 [英] Checking if NSButton is down on drawRect

查看:146
本文介绍了检查NSButton是否在drawRect上关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的自定义drawRect方法中检查我的自定义NSButton当前是否处于按下状态(用户正在单击它).像这样:

I would like to check if my custom NSButton is currently in a pressed state (the user is clicking down on it) in my custom drawRect method. Something like this:

- (void)drawRect:(NSRect)dirtyRect{
    if ([self buttonIsInPressedState]) {
        [[self alternateBGImage] drawInRect:dirtyRect fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0f];
    }else{
        [[self BGImage] drawInRect:dirtyRect fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0f];
    }
    [super drawRect:dirtyRect];
}

您将如何检查类似的内容?有可能吗?

How would you check a thing like that? Is it possible?

解决方案

我最终检查了按钮单元上的mouseDownFlags.不知道这是否是正确"的方法,所以如果您有更好的建议,请告诉我:

I ended up checking the mouseDownFlags on the buttons cell. Don't know if it's the "right" way to do it, so let me know if you have a better suggestion:

- (void)drawRect:(NSRect)dirtyRect{        
    if ([self.cell mouseDownFlags] == 0) {
        [[self BGImage] drawInRect:dirtyRect fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0f];
    }else{
        [[self alternateBGImage] drawInRect:dirtyRect fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0f];
    }

    [super drawRect:dirtyRect];
}

推荐答案

我最终检查了按钮单元格上的mouseDownFlags.不知道这是否是正确"的方法,所以如果您有更好的建议,请告诉我.上面的问题中的解决方案已更新.

I ended up checking the mouseDownFlags on the buttons cell. Don't know if it's the "right" way to do it, so let me know if you have a better suggestion. Solution is updated in the question above.

这篇关于检查NSButton是否在drawRect上关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆