Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6709061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:50:08+00:00 2026-05-26T07:50:08+00:00

I am writing a Cocoa application for OS X, where the user can draw

  • 0

I am writing a Cocoa application for OS X, where the user can draw squares on an NSView instance by clicking with the mouse. Currently I am making the squares disappear after 2 seconds, using the performSelector:withObject:afterDelay: method of NSObject, to force a redraw of the view, with no square included.

However, instead of just disappearing, I would like the squares to fade out gradually. I’ve tried using an NSTimer to periodically force a redraw, with the opacity of the square decreasing to 0 over 2 seconds, but this seems rather inelegant and probably inefficient, especially if I have a lot of squares.

Is there an idiomatic way to do this?

UPDATE: just to clarify, I want each square drawn in the view to have an independent fade starting from the point at which it’s drawn, I’m not looking to fade out the entire view.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T07:50:08+00:00Added an answer on May 26, 2026 at 7:50 am

    The solution I’ve ended up using is to create a CALayer instance for each square, rather than using NSRectFill to draw the squares. The opacity of each CALayer instance can then be independently animated using a CABasicAnimation instance. E.g.

    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"opacity"];
    [animation setFromValue:[NSNumber numberWithFloat:1.]];
    [animation setToValue:[NSNumber numberWithFloat:0.]];
    [animation setDuration:2.];
    [layer setOpacity:0.];
    [layer addAnimation:animation forKey:@"opacity"];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a Mac Cocoa application that will manipulate database files, which can
Writing an application in Cocoa that will take input from the user, format it
I am writing a Cocoa application with Mono embedded. I want to run and
I'm writing a Cocoa application that installs itself as an menulet in the menu
I'm writing a Cocoa application where I have an auto generated app delegate:(MyAppDelegate.h/MyAppDelegate.m) So
I am writing a Cocoa application that makes use of the ParseKit framework (
So, I'm writing a Cocoa application that needs to be able to display web
I'm writing a Cocoa OS X (Leopard 10.5+) end-user program that's using timestamps to
The Problem I'm writing a Cocoa application and I want to raise exceptions that
I am writing the middleware for a cocoa application, and am debating over how

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.