UIView Animations stops working after firing Modal View

I just upgraded my iPhone 4 from iOS 4.2.1 to 4.3.2 and to XCode 4.0.2, and I am facing some fancy uiview animation problems. When I first run my application, this code runs fine:

        [UIView beginAnimations:@"fadeAlphaIn" context:nil];
    [UIView setAnimationDuration:0.5f];
    viewClue.alpha = 1.0f;
    [UIView commitAnimations];

But then, after rejecting the view, and then rejecting the modal view using the standard method:

[self presentModalViewController:more animated:YES];

and

[self dismissModalViewControllerAnimated:YES];

The first animation no longer works. Instead of fading, for example, the viewClue view simply jumps from alpha = 0 to alpha = 1. Similarly, other animations that change the frame property of the other view simply force the frame to go from the initial to the final value without animation. These animations worked great before the modal view was presented and rejected.

, iOS 4.3.2, , , . - ? ? , , .

,

EDIT: , , .

-(void) viewMapfunc
{
    AudioServicesPlaySystemSound(soundID);
    if(mapvisible){
        [UIView animateWithDuration:0.5 
                              delay:0.1
                            options:UIViewAnimationOptionAllowUserInteraction
                         animations:^{
                             map.frame = CGRectMake(0, 350, 320, 27);
                             mapscroll.frame = CGRectMake(0, 27, 320, 0);
                         }
                         completion:nil];

        mapvisible = NO;
        viewMapLabel.text = @"View Map";
    }else {
        [UIView animateWithDuration:0.5 
                              delay:0.1
                            options:UIViewAnimationOptionAllowUserInteraction
                         animations:^{
                             map.frame = CGRectMake(0, 50, 320, 300);
                             mapscroll.frame = CGRectMake(0, 27, 320, 300);
                         }
                         completion:nil];
        mapvisible = YES;
        viewMapLabel.text = @"Hide Map";
    }
}
+5
6

, . - . , . - , , ...

0

:

  • ? , .
  • - ? .
  • , - . - :

-

view.alpha = 1;
[UIView beginAnimations:…];
view.alpha = 0;
[UIView commitAnimations:…];

1 0. . , performSelectorInMainThread: withObject: afterDelay:. 0.

+2

. , , viewWillAppear, viewDidDisappear (, iOS 6 viewDidUnload ).

, , . , - !

0

.

, UIImageViews, , , modal view controller (s). UIImageViews .

, , , , .

/ View Controller UIImageViews -viewDidAppear, -viewDidLoad. , , , UIImageView, , .

, , .

, !

0
source

I used UIView animateWithDuration: I solved it without using a completion block. This is code from a subclass of UIView. In viewWillAppear controller view: I set self.shouldAnimate to YES, and in viewWillDisappear controller view: I set self.shouldAnimate to NO.

-(void)continueRotate {
  if (self.shouldAnimate) {
    [self rotateRadarView:self.radarInner];
  }
}

-(void)rotateRadarView:(UIView *)view {
  [UIView animateWithDuration:0.6 delay:0 options:UIViewAnimationOptionCurveLinear animations:^{
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(continueRotate)];
    [view setTransform:CGAffineTransformRotate(view.transform, M_PI_2)];
  }completion:nil];
}
0
source

I solved this by restarting my animation in my subclass of UIView:

override func willMove(toWindow newWindow: UIWindow?) {
    if newWindow != nil {
        spinner.startSpinning() // Restart any animation here
    }
}
0
source

All Articles