//
// TestBedViewControler_005.m
// UIViewAnimationsTest
//
// Created by mir on 11-4-1.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import "TestBedViewControler_005.h"
@implementation TestBedViewControler_005
/*
// The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
// Custom initialization
}
return self;
}
*/
/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/
-(void) downOrUp:(id)sender{
CGContextRef context=UIGraphicsGetCurrentContext();
[UIView beginAnimations:nil context:context];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:1.0f];
//Apply the animation to the backdrop
UIView *whiteBackdrop=[self.view viewWithTag:100];
if ([(UISegmentedControl *)self.navigationItem.titleView selectedSegmentIndex]) {
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:whiteBackdrop cache:YES];
}else {
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:whiteBackdrop cache:YES];
}
//Exchange the two foreground views
NSInteger purple=[[whiteBackdrop subviews] indexOfObject:[whiteBackdrop viewWithTag:999]];
NSInteger maroon=[[whiteBackdrop subviews] indexOfObject:[whiteBackdrop viewWithTag:998]];
[whiteBackdrop exchangeSubviewAtIndex:purple withSubviewAtIndex:maroon];
[UIView commitAnimations];
}
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.rightBarButtonItem=BARBUTTON(@"Go",@selector(downOrUp:));
UISegmentedControl *segmentedControl=[[UISegmentedControl alloc] initWithItems:[@"Down Up" componentsSeparatedByString:@" "]];
segmentedControl.selectedSegmentIndex=0;
segmentedControl.segmentedControlStyle=UISegmentedControlStyleBar;
self.navigationItem.titleView=segmentedControl;
[segmentedControl release];
UIImageView *view1=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"1.png"]];
view1.tag=999;
UIImageView *view2=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"2.png"]];
view2.tag=998;
UIView *views=[[UIView alloc] init];
views.backgroundColor=[UIColor whiteColor];
views.frame=CGRectMake(0, 0, view1.frame.size.width, view1.frame.size.height);
views.tag=100;
[views addSubview:view1];
[views addSubview:view2];
[self.view addSubview:views];
[views release];
[view1 release];
[view2 release];
}
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
@end