0

I have set the animation like seen in below image. In which UIbutton move from left to right and then top to bottom. Animation work correctly but after completion of animation UIButton comes to its original place before the segue perform. so, it's not look good. I want to set that after the completion of animation UIButton can't come to it's own place before segue .

Here is my try with Image.

   //Move button Left to Right
- (IBAction)btnEasy:(id)sender {
Easy=YES;
NSLog(@"your x is: %f ", self.btnEasy.frame.origin.x);
NSLog(@"your y is: %f ", self.btnEasy.frame.origin.y);

x1=self.btnEasy.frame.origin.x;
y1=self.btnEasy.frame.origin.y;

CGRect screenRect = [[UIScreen mainScreen] bounds];
[UIView animateWithDuration:1.150 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
            self.btnEasy.frame = CGRectMake(screenRect.size.width/1.80, self.btnEasy.frame.origin.y, self.btnEasy.frame.size.width, self.btnEasy.frame.size.height);

    [self performSelector:@selector(btneasyanimation) withObject:self afterDelay:1.160 ];}
                      completion:^(BOOL finished) {

                      }];

  //Move Button top to Bottom

    if (Easy==YES) {
        if (isiPad2 || isiPadAir || isiPadRatina) {
          //[self.view layoutIfNeeded];
                [UIView beginAnimations:nil context:NULL];
                [UIView setAnimationBeginsFromCurrentState:YES];
                [UIView setAnimationDuration:1.0];
                [_btnEasy setFrame:CGRectMake(self.view.frame.origin.x+290, self.view.frame.origin.y+900, self.btnEasy.frame.size.width, self.btnEasy.frame.size.height)];
                [UIView commitAnimations];


        }
     else   if (isiPhone4s) {

            [UIView beginAnimations:nil context:NULL];
            [UIView setAnimationBeginsFromCurrentState:YES];
            [UIView setAnimationDuration:1.0];
            [_btnEasy setFrame:CGRectMake(self.view.frame.origin.x+92, self.view.frame.origin.y+428, self.btnEasy.frame.size.width, self.btnEasy.frame.size.height)];
            [UIView commitAnimations];


        }
    }
  [self performSelector:@selector(segueeMethod) withObject:self afterDelay:1.160 ];

Image :-

enter image description here

Badal Shah
  • 7,541
  • 2
  • 30
  • 65
  • Are you placing the button with Autolayout? if that is the case if you move the frame the button will go to the previous location after the animation finished. – Pablo Carrillo Alvarez Sep 30 '15 at 13:01
  • yes. i have two storyboard for ipad and iphone. in iphone i have used autoresize and in ipad i have used autolayout. but in both storyboard have same issue. – Badal Shah Sep 30 '15 at 13:04

2 Answers2

0

If you are not placing directly the button given it the frame, thus using autolayout (autoresize will end with the same effect). You need to explicitly use autolayout, retain a reference to your constraints and update them (you can search here how to do that) and then set the UIView animation block [button layoutIfNeeded]

You can see a detailed answer about it in this answer

Community
  • 1
  • 1
0

There is an easy and quick way that will work with your current implementation. Provided you know exactly where you want the view to be once the animation is done, you can do the following:

in UIView animateWithDuration: ... assign the final transform (position & orientation) of the view in the completion block, i.e.:

completion:^(BOOL finished) {
// Assign views transform and appearance here, for when the animation completes
}

Hope that helps.

bilo-io
  • 597
  • 3
  • 17