programming4us
programming4us
MOBILE

iPhone Developer : Assembling Views and Animations - Recipe: Swapping Views

- 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
2/9/2015 8:05:13 PM

The UIView animation block doesn’t limit you to a single change. Recipe 1 combines size transformations with transparency changes to create a more compelling animation. It does this by adding several directives at once to the animation block. This recipe performs five actions at a time. It zooms and fades one view into place while zooming out and fading away another and then exchanges the two in the subview array list.

Notice how the viewDidLoad method prepares the back object for animation by shrinking it and making it transparent. When the swap: method first executes, that view will be ready to appear and zoom to size.

This recipe does wait for the animation to finish by providing a delegate and a simplified callback that ignores the parameters of the default callback invocation (animationDidStop:finished:context:). This code hides the bar button after it is pressed and does not return it to view until the animation completes.

Recipe 1. Combining Multiple View Changes in Animation Blocks
- (void) animationFinished: (id) sender
{
self.navigationItem.rightBarButtonItem =
BARBUTTON(@"Swap",@selector(swap:));
}

- (void) swap: (id) sender
{
self.navigationItem.rightBarButtonItem = nil;

UIView *frontObject = [[self.view subviews] objectAtIndex:2];
UIView *backObject = [[self.view subviews] objectAtIndex:1];

CGContextRef context = UIGraphicsGetCurrentContext();
[UIView beginAnimations:nil context:context];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:1.0];

frontObject.alpha = 0.0f;
backObject.alpha = 1.0f;
frontObject.transform = CGAffineTransformMakeScale(0.25f, 0.25f);
backObject.transform = CGAffineTransformIdentity;
[self.view exchangeSubviewAtIndex:1 withSubviewAtIndex:2];
[UIView setAnimationDelegate:self];
Other  
 
Top 10
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
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