Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fade-in / fade-out during an interface rotation

When my iPhone interface rotates, I would like to do a fade-in/fade-out for a specific UIView of a UIViewController... Like...

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.3];
    theView.alpha = 0;
    [UIView commitAnimations];
}

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{   
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.3];
    theView.alpha = 1;
    [UIView commitAnimations];  
}

But the animation doesn't finish before the rotation start (we can see the view starting to self-resize)...

Is there a way to delay rotation start ?

"duration" is the duration of the rotating animation, right ?

like image 213
Damien Debin Avatar asked Sep 03 '10 10:09

Damien Debin


People also ask

What is Fade in Fade out effect?

The Fade In/Fade Out behavior lets you dissolve into and out of any object by ramping the opacity of the object from 0 percent to 100 percent at the start, and then back to 0 percent at the end. You can eliminate the fade-in or fade-out effect by setting the duration of the Fade In Time or Fade Out Time to 0 frames.

What is fade in effect?

Fade in effect can be used to display new video information from a static background. In case of matrix switching, this means visualization of a new video signal to a certain output. On the output the visitor may see the static and still background first and the video signal comes up smoothly.


1 Answers

I found that running the current run loop for the same amount of time as the preceding animation, did in fact delay the rotation.

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    [UIView animateWithDuration:0.25 animations:^{
        theview.alpha = 0.0;
    }];

    [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.25]];
}
like image 110
Måns Severin Avatar answered Sep 24 '22 18:09

Måns Severin