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]解决了这个问题.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |