0

我的 NSRect 正在 BrightnessView.m 中绘制,它连接到名为“brightness”的 xib 上的 NSView 自定义类。PanelController 连接到另一个名为“控制器”的 xib,这就是滑块与操作所在的位置。Panel Controller.h 不能有到 BrightnessView 的出口,因为它没有连接到与具有视图的 xib 相同的 xib。我只需要一个指向亮度视图的指针而不是插座,或者这可以工作吗?我添加了一个常规指针,但这不起作用

//面板 Controller.h 连接到 xib "Controller" 上的文件所有者

#import "BrightnessView.h"

@interface PanelController : NSWindowController
{
   BrightnessView *_myBrightnessView;

}

@property (assign) BrightnessView *BrightnessView;

@end

//面板控制器.m

@synthesize BrightnessView = _myBrightnessView;
- (IBAction)sliderChange:(id)sender;
{
       [_myBrightnessView.self setNeedsDisplay:YES];
}

//BrightnessView.m 连接到 xib "Brightness" 上的 NSView

- (void)drawRect:(NSRect)theRect
        {
            NSLog(@"the view is drawn");
            NSRect contentRect = NSInsetRect([self bounds], 0, 0);
            NSBezierPath *path = [NSBezierPath bezierPath];

            [path moveToPoint:NSMakePoint(_arrowX, NSMaxY(contentRect))];
            [path lineToPoint:NSMakePoint(_arrowX / 2, NSMaxY(contentRect))];
            [path lineToPoint:NSMakePoint(NSMaxX(contentRect), NSMaxY(contentRect))];

            NSPoint topRightCorner = NSMakePoint(NSMaxX(contentRect), NSMaxY(contentRect));
            [path curveToPoint:NSMakePoint(NSMaxX(contentRect), NSMaxY(contentRect))
                 controlPoint1:topRightCorner controlPoint2:topRightCorner];

            [path lineToPoint:NSMakePoint(NSMaxX(contentRect), NSMinY(contentRect))];

            NSPoint bottomRightCorner = NSMakePoint(NSMaxX(contentRect), NSMinY(contentRect));
            [path curveToPoint:NSMakePoint(NSMaxX(contentRect), NSMinY(contentRect))
                 controlPoint1:bottomRightCorner controlPoint2:bottomRightCorner];

            [path lineToPoint:NSMakePoint(NSMinX(contentRect), NSMinY(contentRect))];

            [path curveToPoint:NSMakePoint(NSMinX(contentRect), NSMinY(contentRect))
                 controlPoint1:contentRect.origin controlPoint2:contentRect.origin];

            [path lineToPoint:NSMakePoint(NSMinX(contentRect), NSMaxY(contentRect))];

            NSPoint topLeftCorner = NSMakePoint(NSMinX(contentRect), NSMaxY(contentRect));
            [path curveToPoint:NSMakePoint(NSMinX(contentRect), NSMaxY(contentRect))
                 controlPoint1:topLeftCorner controlPoint2:topLeftCorner];

            [path lineToPoint:NSMakePoint(_arrowX / 2, NSMaxY(contentRect))];
            [path closePath];

            [the_Color setFill];
            [path fill];

            [NSGraphicsContext saveGraphicsState];

            NSBezierPath *clip = [NSBezierPath bezierPathWithRect:[self bounds]];
            [clip appendBezierPath:path];
            [clip addClip];

            [NSGraphicsContext restoreGraphicsState];
        }


        - (void)setArrowX:(NSInteger)value
        {
            _arrowX = value;
        }

www.mediafire.com/?66q8jv3vly1cch4是这个项目的一个例子,它是如何不起作用的。

4

1 回答 1

3

每次用户移动滑块时,您都会创建一个实例。BrightnessView那是错的。您应该使用现有的BrightnessView实例。您PanelController需要一个指向现有实例的属性或实例变量。

于 2012-02-20T20:32:59.383 回答