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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:19:00+00:00 2026-06-07T23:19:00+00:00

I would like to add an animation to a button which make the button

  • 0

I would like to add an animation to a button which make the button remove point A to point B.
And the follow code can do it.But the weird thing is when the button is moved,it can not detect the touch any more.
If you and if I tap the original location of the button,it can trigger the button event.Is anything missing in my code?
Please help me.

- (IBAction)button:(id)sender
{

UIButton    *lineButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[lineButton addTarget:self   action:@selector(press:)forControlEvents:UIControlEventTouchUpInside];
[lineButton setFrame:CGRectMake(50, 50, 50, 50)];
[self.view addSubview:lineButton];
CABasicAnimation *lineAnimation;


lineAnimation = [CABasicAnimation animationWithKeyPath:@"position"];
[lineAnimation setRemovedOnCompletion:NO];
[lineAnimation setDuration:0.15];


[lineAnimation setFillMode:kCAFillModeForwards];
[lineAnimation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];

CGRect rect = CGRectMake(100, 200, 50, 50);
    lineAnimation.fromValue = [NSValue valueWithCGPoint: CGPointMake(50, 50)];
    lineAnimation.toValue = [NSValue valueWithCGPoint:CGPointMake(CGRectGetMidX(rect),   CGRectGetMidY(rect))];
[lineAnimation setAutoreverses:NO];
[lineButton.layer addAnimation:lineAnimation forKey:@"line"];
}
  • 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-06-07T23:19:02+00:00Added an answer on June 7, 2026 at 11:19 pm

    You have to set the new frame and layer to your button’s frame/layer after the addAnimation method like:

    lineButton.frame = rect
    lineButton.layer.frame = rect
    

    Or you can simply use animation blocks (Easier to use, code looks nice, etc..) like:

    [UIView animateWithDuration:0.15 animations:^{
      lineButton.frame = CGRectMake(100, 200, 50, 50);
    }];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a animation of moving blocks but I would like to add feature
I would like to add a NSProgressIndicator . I have a button which enable
I would like to add animation effect to following code when showing tree items.
I would like to add a custom calculation method to a managed object (which
I would like to add a small dice-rolling effect to my Javascript code. I
I would like to create an animation to demonstrate LDPC coding which is based
I would like to add a progress animation to a function so that it
I have done the candle animation tutorial here but I would like to save
I would like to add the same sprite animation multiple times. I've tried it
I have in mind one simple application, but I would like to add some

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.