0

我有一个测试视图,我在其中进行一些图形测试。目前我有一个方法drawCircle绘制一个带阴影的彩色圆圈。

awakeFromNib中,我设置了一个计时器timerAction ,它每 0.5 秒触发一次 timerAction 方法:setNeedsDisplay : YES

这种方式drawRect触发drawCircle绘制另一个具有随机颜色和阴影的圆圈。请参阅下面的方法。

到目前为止一切正常。我想顺利地从一个色环切换到另一个色环。现在一点都不顺畅。它只是突然从一个切换到另一个。

我尝试了几件事,但我就是不知道该怎么做。

有任何想法吗?

罗纳德。

TimeCircle2.h

  //
  //  TimeCircle2.h
  //  Egg&Breakfast
  //
  //  Created by Ronald Hofmann on 29.12.12.

  #import <Cocoa/Cocoa.h>

  @interface TimeCircle2 : NSView {

     CGFloat CGFalpha       ;
     CGFloat CGFblue        ;
     CGFloat CGFgreen       ;
     CGFloat CGFred         ;

     NSURL    *pathToFolder ;
     NSShadow *shadow       ;
     NSTimer  *timer        ;

     NSColor
     *myRedColor,*myGreenColor,*myRedBGColor,*myGreyColor,*myRandomColor,
     *mydarkGreyColor,*myYellowBGColor,*myBlueColor,*myBlackColor,*myDkGreenColor;

     IBOutlet NSSliderCell
     *slideHourCell, *slideMinCell, *slideSecCell ;

     float
     lineTheWidth,circleWidth,circleHeight,spaceX,spaceY,intervall,
     center1,center2,shadow1,shadow2,ankathete,gegenkathete,winkelAlpha;

     BOOL     flagButtonWasClicked ;
     int      drawRectCount,getHTime, getMTime,getSTime,goalTS ;

     IBOutlet TimeCircle2 *myTimeCircleView ;
     IBOutlet NSButton    *butStart         ;
     IBOutlet NSPanel     *mainPanel        ;
     IBOutlet NSButton    *boxForEver       ;
     IBOutlet NSButton    *boxMakeSound     ;
     IBOutlet NSButton    *timerFlagSwitch  ;

     IBOutlet NSSlider    *slideHour        ;
     IBOutlet NSSlider    *slideMin         ;
     IBOutlet NSSlider    *slideSec         ;
     IBOutlet NSSlider    *angleSlider      ;
     IBOutlet NSSlider    *volumeAdjust     ;
     IBOutlet NSTextField *txtRemark        ;
     IBOutlet NSProgressIndicator *progInd  ;

     TimeCircle2          *myTimeCircle     ;

  }

  @end

TimeCircle2.m

     //
     //  TimeCircle2.m
     //  Egg&Breakfast
     //
     //  Created by Ronald Hofmann on 29.12.12.

  #import "TimeCircle2.h"
  #import "NSObject+Utilities.h"

  @implementation TimeCircle2

  #define overLine 15
  #define kProject        @"EggBreakfast"

  #pragma mark Global Declarations
  NSBezierPath *path;
  NSBezierPath *path1,*path2,*path3,*path4;
  NSPoint  centerPoint1,centerPoint2      ;
  NSPoint  centerPoint;

  BOOL     flagButtonWasClicked           ;
  float    liveAngle,radius,transparency,intvalSet  ;


  #pragma mark Methods
  - (id)initWithFrame:(NSRect)frame
  {
     self = [super initWithFrame:frame];
     if (self) {
           // Initialization code here.
     }

     return self;
  }

  - (void) awakeFromNib      {

     timer = [[NSTimer scheduledTimerWithTimeInterval: 0.5
                                               target:self
                                             selector:@selector(timerAction:)
                                             userInfo:nil
                                              repeats:YES] retain];
  }


  - (void)drawRect:(NSRect)dirtyRect
  {
     [self drawCircle];
  }


  - (void) timerAction:(NSTimer *)aTimer {
     [self setNeedsDisplay:YES];
  }


  - (void) drawCircle        {

     NSRect bounds      = self.bounds ;
     NSBezierPath *path = [NSBezierPath bezierPath];

     shadow1 = 4; shadow2 = -shadow1;

     shadow = [NSShadow new];
     float setShadow   = 0.2f          ;

     float radius = 5+(circleHeight/2);

     spaceX       = (bounds.size.width  - circleWidth )/2.0f;
     spaceY       = (bounds.size.height - circleHeight)/2.0f;

     setShadow   = 0.2f          ;

     lineTheWidth = 1.0f;

     circleWidth  =  bounds.size.width  *0.80f;
     circleHeight =  bounds.size.height *0.80f;

     radius = 12+(circleHeight/2);

     spaceX       = (bounds.size.width  - circleWidth )/2.0f;
     spaceY       = (bounds.size.height - circleHeight)/2.0f;

     center1      =  bounds.size.width /2.0f;
     center2      =  bounds.size.height/2.0f;

     centerPoint  =  NSMakePoint(center1,center2);

     path = [ NSBezierPath bezierPathWithOvalInRect:
             (NSRect) {{ spaceX, spaceY },{ (circleWidth), (circleHeight)}}] ;

     [path setLineWidth:2.0000f];
     [[self ccRandom:0.6f :0.0f]  setStroke];

     [shadow setShadowColor: [NSColor blackColor]];
     [shadow setShadowBlurRadius: 5.0f];

     [shadow setShadowOffset: NSMakeSize(shadow1,shadow2)];
     [shadow set];

     [path stroke];

  }

  @end
4

0 回答 0