加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

objective-c – 检查NSRutton是否在drawRect上关闭

发布时间:2020-12-16 03:26:32 所属栏目:百科 来源:网络整理
导读:我想在我的自定义drawRect方法中检查我的自定义NSButton当前是否处于按下状态(用户正在点击它).像这样的东西: - (void)drawRect:(NSRect)dirtyRect{ if ([self buttonIsInPressedState]) { [[self alternateBGImage] drawInRect:dirtyRect fromRect:NSZeroR
我想在我的自定义drawRect方法中检查我的自定义NSButton当前是否处于按下状态(用户正在点击它).像这样的东西:
- (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];
}

你会怎么检查这样的事情?可能吗?

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

- (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];
}

解决方法

我通过检查[self isHighlighted]解决了这个问题.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读