• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Smooth Animation
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Smooth Animation


  • Subject: Re: Smooth Animation
  • From: Daniel Waylonis <email@hidden>
  • Date: Fri, 11 Jun 2004 17:50:45 -0700

On Jun 11, 2004, at 4:25 PM, Rhon Fitzwater wrote:

> Right now I have my window so its alpha setting is set to 1.0 when the
> mouse enters the window and 0.2 when the mouse exits, using this code:
>
> //mouse entered exited window code below
> - (void)viewDidMoveToWindow {
> [self addTrackingRect:[self frame] owner:self userData:nil
> assumeInside:NO];
> [super viewDidMoveToWindow];
> }
>
> - (void)mouseEntered:(NSEvent *)event {
> NSLog(@"Mouse Entered");
> [[self window] setAlphaValue:1.0];
>
> }
>
> - (void)mouseExited:(NSEvent *)event {
> NSLog(@"Mouse Exited");
> [[self window] setAlphaValue:0.2];
> }
> //end of mouse entered or exited window code
>
> What I want to know how to do is make the transition between alpha
> settings smooth. gradually increase or decrease alpha settings. Can
> someone tell me how this can be done, possible with some coding
> examples?

Hi Rhon,

Try this:

- (void)viewDidMoveToWindow {
[self addTrackingRect:[self frame] owner:self userData:nil
assumeInside:YES];
[super viewDidMoveToWindow];
}

static float windowAlphaIncrement = 0.15;
static float windowAlphaCurrentIncrement;
static float windowAlphaMin = 0.2;
static float windowAlphaMax = 1.0;
static float windowAlphaFadeRate = 1.0 / 15.0;

- (void)changeTransparency:(NSTimer *)timer
{
float alpha = [[self window] alphaValue];
BOOL reschedule = NO;

alpha += windowAlphaCurrentIncrement;

// Reschedule timer if we haven't reached desired value
if (windowAlphaCurrentIncrement > 0)
{
if (alpha < windowAlphaMax)
reschedule = YES;
else
alpha = windowAlphaMax;
}
else
{
if (alpha > windowAlphaMin)
reschedule = YES;
else
alpha = windowAlphaMin;
}

if (reschedule)
[NSTimer scheduledTimerWithTimeInterval:windowAlphaFadeRate
target:self selector:@selector(changeTransparency:) userInfo:nil
repeats:NO];

[[self window] setAlphaValue:alpha];
}

- (void)mouseEntered:(NSEvent *)event {
NSLog(@"Mouse Entered");

windowAlphaCurrentIncrement = windowAlphaIncrement;
[NSTimer scheduledTimerWithTimeInterval:windowAlphaFadeRate
target:self selector:@selector(changeTransparency:) userInfo:nil
repeats:NO];
}

- (void)mouseExited:(NSEvent *)event {
NSLog(@"Mouse Exited");

windowAlphaCurrentIncrement = -windowAlphaIncrement;
[NSTimer scheduledTimerWithTimeInterval:windowAlphaFadeRate
target:self selector:@selector(changeTransparency:) userInfo:nil
repeats:NO];
}

Dan
_________________________________________________
Dan Waylonis email@hidden
Software Engineer http://www.nekotech.com
nekotech SOFTWARE 650.964.2490 (O)
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


  • Follow-Ups:
    • Re: Smooth Animation
      • From: Rhon Fitzwater <email@hidden>
References: 
 >Smooth Animation (From: Rhon Fitzwater <email@hidden>)

  • Prev by Date: Re: debugging my first application
  • Next by Date: Re: Smooth Animation
  • Previous by thread: Smooth Animation
  • Next by thread: Re: Smooth Animation
  • Index(es):
    • Date
    • Thread