gpt4 book ai didi

objective-c - 自定义 NSSliderCell

转载 作者:太空狗 更新时间:2023-10-30 03:30:52 24 4
gpt4 key购买 nike

我已经完成了一个自定义 slider 单元格的实现,该单元格可以使用滚动条和旋钮的图像进行绘制。现在唯一的障碍是,当我快速拖动旋钮时,图像会变得困惑。我已经发布了一个屏幕截图。

Screenshot

代码如下:

#import "customSliderCell.h"
@implementation customSliderCell
- (void)drawKnob:(NSRect)knobRect {

NSImage * knob = knobImage;
[[self controlView] lockFocus];
[knob
compositeToPoint:NSMakePoint(knobRect.origin.x,knobRect.origin.y+knobRect.size.height)
operation:NSCompositeSourceOver];

[[self controlView] unlockFocus];
}
- (void)drawBarInside:(NSRect)rect flipped:(BOOL)flipped {
rect.size.height = 8;

NSRect leftRect = rect;
leftRect.origin.x=0;
leftRect.origin.y=2;
leftRect.size.width = knobrect.origin.x + (knobrect.size.width);
[leftBarImage setSize:leftRect.size];
[leftBarImage drawInRect:leftRect fromRect: NSZeroRect operation: NSCompositeSourceOver fraction:1];

NSRect rightRect = rect;
rightRect.origin.x=0;
rightRect.origin.y=2;
rightRect.origin.x = knobrect.origin.x;
[rightBarImage setSize:rightRect.size];
[rightBarImage drawInRect:rightRect fromRect: NSZeroRect operation: NSCompositeSourceOver fraction:1];
}

啊,我太接近了。任何关于为什么会发生这种情况以及如何解决它的帮助将不胜感激,谢谢!

最佳答案

好的,所以它想通了。显然, slider 试图变得聪明,只在旋钮所在的位置绘制。所以显然我必须通过覆盖 slider 类中的 setNeedsDisplayInRect 来始终使矩形无效。

#import "customSlider.h"

@implementation customSlider
-(void)setNeedsDisplayInRect:(NSRect)invalidRect{
[super setNeedsDisplayInRect:[self bounds]];
}
@end

关于objective-c - 自定义 NSSliderCell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3985816/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com