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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T18:42:27+00:00 2026-06-07T18:42:27+00:00

i have impletemented a button jiggle animation.where pressing a button wobbles ,but the problem

  • 0

i have impletemented a button jiggle animation.where pressing a button wobbles ,but the problem is the animation does’nt stop and getting an error in [self.layer removeAllAnimations];
below is the code;

 -(IBAction)button1Clicked:(id)sender
 {
UIButton *no1 =sender;
output= [self answerCheck:no1.titleLabel.text];
self.label.text=output;
[self enableOptions:NO];
[self loadingView];
[self startJiggling:2];

 }
- (void)startJiggling:(NSInteger)count
{

    CGAffineTransform leftWobble = CGAffineTransformMakeRotation(degreesToRadians( kAnimationRotateDeg * (count%2 ? +1 : -1 ) ));
    CGAffineTransform rightWobble = CGAffineTransformMakeRotation(degreesToRadians( kAnimationRotateDeg * (count%2 ? -1 : +1 ) ));
    CGAffineTransform moveTransform = CGAffineTransformTranslate(rightWobble, -kAnimationTranslateX, -kAnimationTranslateY);
    CGAffineTransform conCatTransform = CGAffineTransformConcat(rightWobble, moveTransform);

    self.btnOption1.transform = leftWobble;  // starting point

    [UIView animateWithDuration:0.1
                          delay:(count * 0.08)
                        options:UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse
                     animations:^{ self.btnOption1.transform = conCatTransform; }
                     completion:nil];
 [self stopJiggling];
}

-(void)stopJiggling 
{
    [self.btnOption1.layer removeAllAnimations];
    self.btnOption1.transform = CGAffineTransformIdentity;   // Set it straight 
}
  • 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-07T18:42:29+00:00Added an answer on June 7, 2026 at 6:42 pm

    You’re setting the animation on self.btnOption1, so you would need to remove it from self.btnOption1:

    - (void)stopJiggling {
        [self.btnOption1.layer removeAllAnimations];
        self.btnOption1.transform = CGAffineTransformIdentity;
    }
    

    but in fact if you just set the transform property of the button again, outside of an animation block, it will remove the animation:

    - (void)stopJiggling {
        self.btnOption1.transform = CGAffineTransformIdentity;
    }
    

    (This worked in my test project.)

    Update:

    I notice that you’re starting the animation with a delay, and you’re calling stopJiggling immediately after you call animateWithDuration:.... I don’t know why you’re using a delay or why you’re calling stopJiggling immediately.

    I created a test case to match your code:

    @implementation ViewController {
        __unsafe_unretained IBOutlet UIButton *btnOption1;
    }
    
    - (IBAction)startJiggling {
        btnOption1.transform = CGAffineTransformMakeRotation(-.1);
        [UIView animateWithDuration:.1 delay:2 * 0.08 options:UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse animations:^{
            btnOption1.transform = CGAffineTransformMakeRotation(.1);
        } completion:nil];
        [self stopJiggling];
    }
    
    - (void)stopJiggling {
        [btnOption1.layer removeAllAnimations];
        btnOption1.transform = CGAffineTransformIdentity;
    }
    
    @end
    

    I hooked up my btnOption1 ivar to a button, and connected the button to the startJiggling method. With the code as shown, clicking the button does nothing, because the animation is removed immediately after it is added. If I comment out the removeAllAnimations message, clicking the button makes the button start jiggling and it jiggles forever. I tested on the iPhone 4.3 simulator, the iPhone 5.0 simulator, the iPhone 5.1 simulator, and my iPhone 4S running iOS 5.1.

    So, I could not reproduce your problem. Sending removeAllAnimations removes the animation in my test.

    I suspect that you just want the animation to repeat twice and then stop (since you have an argument named count and you’re passing 2). If that’s what you want to do, you can do it like this:

    - (IBAction)startJiggling {
        btnOption1.transform = CGAffineTransformMakeRotation(-.1);
        [UIView animateWithDuration:.1 delay:2 * 0.08 options:UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse animations:^{
            [UIView setAnimationRepeatCount:2];
            btnOption1.transform = CGAffineTransformMakeRotation(.1);
        } completion:^(BOOL completed){
            btnOption1.transform = CGAffineTransformIdentity;
        }];
    }
    

    You set the repeat count inside the animation block using +[UIView setAnimationRepeatCount:], and you restore the button’s transform in the completion block.

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

Sidebar

Related Questions

I have implemented pagination to my data, but the problem is I only have
I have implemented gplus button on the site, and it works perfect, but when
I have a MVP application implemented. Back button is working fine. I'd like to
I have implemented Facebook into my app but now I find that whenever I
I have implemented my custom button inheriting from CButton and drawing it by using
Hi I have implemented this code: Button goToRegister = (Button) findViewById(R.id.reg); goToRegister.setOnClickListener(new View.OnClickListener() {
I have implemented RPCService, RPCServiceAsync & RPCServieImpl. On clicking a button a service in
I have implemented button's onLongClickListener in Android Dialog which auto-decreases number using timers. Here
I have implemented a listbox with buttons as follows <Button.Content> <StackPanel Orientation=Horizontal Width=440 Height=210>
i am jsgrid i want have implemented the add row button. when i click

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.