SetNeedsDisplay не рисует NSRect

Мой NSRect рисуется в BrightnessView.m, и он связан с пользовательским классом NSView на XIB, называемом "яркость". PanelController подключен к другому XIB, называемому "контроллер", и именно здесь находится ползунок с действием. Panel Controller.h не может иметь выхода к BrightnessView, потому что он не подключен к той же плате, что и представление. Вместо розетки мне понадобится просто указатель на яркость или это будет работать? Я добавил обычный указатель, но это не сработает

// Панель Controller.h подключена к владельцу файла на xib "Контроллер"

#import "BrightnessView.h"

@interface PanelController : NSWindowController
{
   BrightnessView *_myBrightnessView;

}

@property (assign) BrightnessView *BrightnessView;

@end

//Panel Controller.m

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

//BrightnessView.m подключен к NSView на XIB "Яркость"

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

http://%5Bmediafire.com/?66q8jv3vly1cch4%5D является примером этого проекта и того, как он не будет работать.

1 ответ

Решение

Вы создаете новый экземпляр BrightnessView каждый раз, когда пользователь перемещает ползунок. Это не правильно. Вы должны использовать свой существующий BrightnessView пример. Ваш PanelController Требуется переменная свойства или экземпляра, которая указывает на существующий экземпляр.

Другие вопросы по тегам