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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:14:29+00:00 2026-05-28T19:14:29+00:00

I got view animations to work perfectly in Xcode (slide off the screen on

  • 0

I got view animations to work perfectly in Xcode (slide off the screen on a button click with CGRect.) Unfortunately I have to click the button twice to execute the animation. What have I done wrong? I appreciate any feedback

Here’s my .H code

@interface AnimationBlocksViewController : UIViewController{
    IBOutlet UIView *theview;
    IBOutlet UIView *theview2;

    BOOL isAnimated;
    BOOL switchback;
}

-(IBAction)animate:(id)sender;
-(IBAction)change:(id)sender;

Here’s my .M code

-(IBAction)animate:(id)sender;{
    if (isAnimated) {

        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
        [UIView setAnimationDuration:0.5];
        [theview setFrame:CGRectMake(0, 0, 320, 460)];
        [theview2 setFrame:CGRectMake(320, 0, 320, 460)];
        [UIView commitAnimations];
        isAnimated=NO;

    }


    else{

        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
        [UIView setAnimationDuration:0.5];
        [theview setFrame:CGRectMake(-320, 0, 320, 460)];
        [theview2 setFrame:CGRectMake(0, 0, 320, 460)];
        [UIView commitAnimations];
        isAnimated=YES;

    }
}

-(IBAction)change:(id)sender;{
    if (switchback) {

        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
        [UIView setAnimationDuration:0.5];
        [theview2 setFrame:CGRectMake(0, 0, 320, 460)];
        [UIView commitAnimations];
        switchback=NO;

    }


    else{

        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
        [UIView setAnimationDuration:0.5];
        [theview2 setFrame:CGRectMake(320, 0, 320, 460)];
        [theview setFrame:CGRectMake(0, 0, 320, 460)];
        [UIView commitAnimations];
        switchback=YES;

    }
}

It works but I have to double click to trigger the animation, what have I done wrong?
Thank you

  • 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-28T19:14:30+00:00Added an answer on May 28, 2026 at 7:14 pm

    After your initial double click, does a subsequent single click trigger the animation properly? If so, it may be that you haven’t explicitly initialised your BOOL variables, though they should default to NO. Try doing that and see if it helps.

    If you always need to do two taps to animate, maybe try inserting a call to the run loop to see if it’s only processing the animation after running on your application thread for a while i.e. it could be that only when it comes to process a second click event does it actually go and fetch any pending animations and execute them. The code for that would be (after you set isAnimated and call commitAnimations):

    [[NSRunLoop mainRunLoop] runMode:NSRunLoopCommonModes beforeDate:[NSDate date]];
    

    Not sure whether you can just use nil for a date but try that too if you like.

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

Sidebar

Related Questions

I'm trying to understand how view animations work in iOS; i currently have an
I have the following problem: I got a view with two text fields and
I got a view where I list files and I got a Delete button
I have got a view controller with a UIView and a navigation controller configured
I got a view that inherits : System.Web.Mvc.ViewPage<IEnumerable<MyProjects.Models.MyAccountWrapper>> In this view I list data
Ive got a view helper in library/my/view/helper/gravatar and so in any view I can
I've got a view in my app that does pretty much everything, and I
I've got a view function that has to decide which form to use depending
I'm working in an ASP.NET 3.5 MVC application where i've got a view with
In my View I got a ListView bound to a CollectionView in my ViewModel,

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.