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

  • Home
  • SEARCH
  • 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 7430029
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:04:29+00:00 2026-05-29T09:04:29+00:00

I have the following situation: From within a view controller, I go about creating

  • 0

I have the following situation:

From within a view controller, I go about creating an arbitrary number of transparent UIButtons which toogle the appearance and disappearance of UIViews over the controller’s main view. Right now, when my “zoom in” and “zoom out” methods are called, there’s code for modifying the default animation of two CALayer properties (just duration really). This code then gets called every time the actions take place. But I’d like to set the animation code once inside the layer and not have it in the zoom methods. I’ll explain more after I show the basic idea:

The buttons/sensors creation code is too long to post (and not that relevant to the real question), but it’s something along the lines of this pseudo code:

- (void) createSensors:[number of sensors]
{
  for(number of sensors)
  {
    create UIVIew with some content;
    create transparent UIBUtton as sensor and place somewhere in main view;
    calculate a transform to "shrink" the UIView's layer to the size and position of the button.
    apply transform;
    set the UIVIew's layer opacity to 0;
    add UIVIew to main view 
    (but the rest of my interface is in a container view, so I can dim the screen and have this view displayed in a modal-like way.)
    do some tagging so the button's tag can later be used to retrieve this view and transform.
    }
}

Now, when a sensor is clicked, I perform a “zoom in” for the view associated with the sensor/view. I actually dim the screen to white, and animate the view’s (the layer’s really) position and scaling to the center of the screen. And on clicking a button in the view, I do the opposite to dismiss it. This is the code:

- (void)animateZoomIn:(UIButton*)sender
{  
  NSString *sourceTagKey = [NSString stringWithFormat:@"%i",sender.tag]; 
  AnimationSettings *settings = [zoomTransforms objectForKey:sourceTagKey];

  UIView *newBox = [[self.view subviews] objectAtIndex:sender.tag]; 
  activeZoomBox = newBox;

  CABasicAnimation *a = [CABasicAnimation animation];
  a.duration = .4;
  [mainCanvas.layer addAnimation:a forKey:@"opacity"];

  a = [CABasicAnimation animation];
  a.duration = 1;
  [activeZoomBox.layer addAnimation:a forKey:@"opacity"];

  a = [CABasicAnimation animation];
  a.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
  a.duration = .5;
  [activeZoomBox.layer addAnimation:a forKey:@"transform"];  

  [mainCanvas setUserInteractionEnabled:NO];

  if([settings wantsBackgroundFade])
    [mainCanvas.layer setOpacity:.2];

  [activeZoomBox.layer setOpacity:1];  
  [activeZoomBox.layer setTransform:CATransform3DIdentity];
}


- (void)animateZoomOut:(UIButton*)sender
{
  NSString *sourceTagKey = [NSString stringWithFormat:@"%i",sender.tag]; 
  AnimationSettings *settings = [zoomTransforms objectForKey:sourceTagKey];

  CABasicAnimation *a = [CABasicAnimation animation];
  a.duration = .4;
  [mainCanvas.layer addAnimation:a forKey:@"opacity"];

  a = [CABasicAnimation animation];
  a.duration = 1;
  [activeZoomBox.layer addAnimation:a forKey:@"opacity"];

  a = [CABasicAnimation animation];
  a.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
  a.duration = .5;
  [activeZoomBox.layer addAnimation:a forKey:@"transform"];


  [mainCanvas setUserInteractionEnabled:YES];

  if([settings wantsBackgroundFade])
    [mainCanvas.layer setOpacity:1];

  [activeZoomBox.layer setOpacity:0];  
  [activeZoomBox.layer setTransform:[settings transform]];
}

So, the question:

I’d like to not have this kind of code:

CABasicAnimation *a = [CABasicAnimation animation];
  a.duration = .4;
  [mainCanvas.layer addAnimation:a forKey:@"opacity"];

in the action methods. I’d rather replace the animation once and make it “permanent” for each layer created and for the mainCanvas view. For instance, I’d prefer to have this code once on the controller’s init method and forget about it:

CABasicAnimation *a = [CABasicAnimation animation];
    a.duration = .4;
    NSMutableDictionary *animations = [NSMutableDictionary dictionaryWithDictionary:[mainCanvas.layer actions]];
    [animations setObject:a forKey:@"opacity"];
    [mainCanvas.layer setActions:animations];

Then, whenever I’d call [mainCanvas setOpacity:] it would last .4 secs by default. With a delegate-less CALayer it’d work.But in this case, my layers have their views as delegates, which have precedence over the actions dictionary, and I sort of need the views as delegates..

So is there a way to still have the layers respond to the dictionary instead? And if not, what would be the best way to “permanently replace” or add animations to these layers, so that the animations are contained in the layer objects (which is why I’d prefer to not override the view’s delegate methods for the CAAction Protocol)?

  • 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-29T09:04:30+00:00Added an answer on May 29, 2026 at 9:04 am

    Why not just override -actionForLayer:forKey: on the UIView to provide the action you want on the important keys (and call super for the others)? There is no way to change the precedence, so your only options are implement -actionForLayer:forKey: or go with the manual animations.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following situation: There is a tool that gets an XSLT from
I have the following situation. Im getting data from an external system in the
I have the following situation: I built an Access form with a subform (which
I have the following situation and I'm expecting some expert advise from SO folks.
I have the following situation: I have a loop which could loop any amount
I have the following multi-table inheritance situation: from django.db import Models class Partner(models.Model): #
I have following situation: I have loged user, standard authentication with DB table $authAdapter
I have following situation. A main table and many other tables linked together with
I have following situation. In a constructor of a pseudo class I attach a
I have following situation (simplified, of course): MyDomain.groovy: class MyDomain { MyAnotherDomain anotherDomain //

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.