programming4us
programming4us
MOBILE

iPhone Developer : Assembling Views and Animations - Recipe: Fading a View In and Out

- How To Install Windows Server 2012 On VirtualBox
- How To Bypass Torrent Connection Blocking By Your ISP
- How To Install Actual Facebook App On Kindle Fire

At times, you want to add information to your screen that overlays your view but does not of itself do anything. For example, you might show a top scores list or some instructions or provide a context-sensitive tooltip. Recipe 1 demonstrates how to use a UIView animation block to fade a view into and out of sight. This recipe follows the most basic animation approach. It creates a surrounding view animation block and then adds the single line of code that sets the alpha property.

One thing this recipe does not do is wait for the animation to finish. The change in the bar button item gets called as soon as the animations are committed, nearly a second before they end. If you tap the Fade In/Fade Out button quickly (you may want to slow the animation duration to see this better), you discover that the new animation starts up, replacing the old one, creating a visual discontinuity.

To address this, you might want to add a call to UIView with setAnimationBeginsFromCurrentState:, setting the argument to YES. This tells the iPhone to use the current state of the ongoing animation to start the next animation, avoiding that jump.

Recipe 1. Animating Transparency Changes to a View’s Alpha Property
@implementation TestBedViewController

- (void) fadeOut: (id) sender
{
CGContextRef context = UIGraphicsGetCurrentContext();
[UIView beginAnimations:nil context:context];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:1.0];
[[self.view viewWithTag:999] setAlpha:0.0f];
[UIView commitAnimations];
self.navigationItem.rightBarButtonItem =
BARBUTTON(@"Fade In",@selector(fadeIn:));
}

- (void) fadeIn: (id) sender
{
CGContextRef context = UIGraphicsGetCurrentContext();
[UIView beginAnimations:nil context:context];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:1.0];
[[self.view viewWithTag:999] setAlpha:1.0f];
[UIView commitAnimations];
self.navigationItem.rightBarButtonItem =
BARBUTTON(@"Fade Out",@selector(fadeOut:));
}

- (void) viewDidLoad
{
self.navigationItem.rightBarButtonItem =
BARBUTTON(@"Fade Out",@selector(fadeOut:));
}
@end

Other  
 
Soccer Highlights
- VIDEO Lyon 4 – 0 Apollon Limassol (Europa League) Highlights
- VIDEO Everton 1 – 5 Atalanta (Europa League) Highlights
- VIDEO AC Milan 5 – 1 Austria Wien (Europa League) Highlights
- VIDEO FC Cologne 1 – 0 Arsenal (Europa League) Highlights
- VIDEO Nice 3 – 1 Zulte-Waregem (Europa League) Highlights
- VIDEO Braga 3 – 1 Hoffenheim (Europa League) Highlights
- VIDEO Lazio 1 – 1 Vitesse (Europa League) Highlights
- VIDEO Konyaspor 1 – 1 Marseille (Europa League) Highlights
- VIDEO Athletic Bilbao 3 – 2 Hertha Berlin (Europa League) Highlights
- VIDEO Salzburg 3 – 0 Vitoria de Guimaraes (Europa League) Highlights
- VIDEO Ludogorets Razgrad 1 – 2 Istanbul Basaksehir (Europa League) Highlights
- VIDEO FC Astana 2 – 3 Villarreal (Europa League) Highlights
REVIEW
- First look: Apple Watch

- 3 Tips for Maintaining Your Cell Phone Battery (part 1)

- 3 Tips for Maintaining Your Cell Phone Battery (part 2)
programming4us programming4us
programming4us
 
 
programming4us