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 7501979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T20:42:51+00:00 2026-05-29T20:42:51+00:00

I have a UIView instance that I am animating using CAKeyframeAnimation . It is

  • 0

I have a UIView instance that I am animating using CAKeyframeAnimation. It is a looping animation and will be constantly in motion. However, I need to allow user interaction with the item (responding to taps, to be exact). Because CoreAnimation is only moving the presentation layer and not the model, I cannot use a UIButton instance, for example, to essentially get the touchUpInside events.

Consider the following basic example layout:

enter image description here

I am using the blue box for touch events by overriding the touchesEnded:withEvent: method on a UIView subclass. I am then bubbling that event through an NSNotification (I really don’t want to introduce a lot of coupling to handle this event) to the containing view controller, which then does a hitTest: on the red box being animated.

All of this seems rather hacky to just be able to touch an animated UIView. What are some of the best patterns for handling touches for animated UIView/CALayer instances?

  • 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-29T20:42:51+00:00Added an answer on May 29, 2026 at 8:42 pm

    Tracking the touch in the superview is correct I believe. But I would do hit testing in the superview rather than posting a notification to the view controller. Something like this:

    Create a MYAnimationContainerView class (the blue box).

    Give it a delegate or block callback that the owning view controller sets. For example:

    __weak id weakSelf = self;
    MYAnimationContainerView *view = [[MYAnimationContainerView alloc] initWithTouchCallback:^(UIView *touchedView){
      [weakSelf handleTouchToView:touchedView];
    }];
    

    In MYAnimationContainerView, override both touchesBegan:withEvent: and touchesEnded:withEvent:. In began, perform a hit test on the presentation layer of the moving view(s). Keep track of which one (if any) was touched. In ended, perform another hit test. If it’s the same view, then call your callback.

    The above could just as easily be implemented with a delegate protocol rather than a block. I’ve just been getting in the habit of preferring blocks over one-method delegate protocols.

    You could also implement it with target/selector, but that pattern has gotten to be a bit of a hassle with ARC, and I tend to discourage its use today.

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

Sidebar

Related Questions

I have a UIView that will eventually contain about 2 screens worth of information.
I have a UIView that contains a number of CALayer subclasses. I am using
I have the following code in a UIView subclass that will move it off
I have a UIView subclass ( CustomView for purposes of this question) that has
I have a UIView that has several UIImageViews as subviews. Each of these subviews
I have a UIView subclass that draws itself when -drawRect: is called. It only
I have a UIView whose layers will have sublayers. I'd like to assign delegates
In the following code I have a view object that is an instance of
I have a custom UIView subclass that i'm trying to use as a header
I have a UIView subclass that I assign to a text field as follows:

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.