首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Iphone >

iPhone 翻旋动画

2012-07-18 
iPhone 翻转动画? ? //// ?TestBedViewControler_003.m// ?UIViewAnimationsTest//// ?Created by mir on

iPhone 翻转动画

? ? //

// ?TestBedViewControler_003.m

// ?UIViewAnimationsTest

//

// ?Created by mir on 11-4-1.

// ?Copyright 2011 __MyCompanyName__. All rights reserved.

//

?

#import "TestBedViewControler_003.h"

?

?

@implementation TestBedViewControler_003

?

/*

?// 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) animationFinished: (id) sender

{

self.navigationItem.rightBarButtonItem = BARBUTTON(@"Flip", @selector(filps:));

}

?

-(void) filps:(id) sender{

self.navigationItem.rightBarButtonItem=nil;

CGContextRef context = UIGraphicsGetCurrentContext();

[UIView beginAnimations:nil context:context];

[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

[UIView setAnimationDuration:1.0f];

UIView *whiteBackdrop=[self.view viewWithTag:100];

if ([(UISegmentedControl *)self.navigationItem.titleView selectedSegmentIndex]) {

[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:whiteBackdrop cache:YES];

}else {

[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:whiteBackdrop cache:YES];

}

NSInteger purple = [[whiteBackdrop subviews] indexOfObject:[whiteBackdrop viewWithTag:999]];

NSInteger maroon = [[whiteBackdrop subviews] indexOfObject:[whiteBackdrop viewWithTag:998]];

[whiteBackdrop exchangeSubviewAtIndex:purple withSubviewAtIndex:maroon];

[UIView setAnimationDelegate:self];

[UIView setAnimationDidStopSelector:@selector(animationFinished:)];

[UIView commitAnimations];

}

?

?

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.

- (void)viewDidLoad {

? ? [super viewDidLoad];

self.navigationItem.rightBarButtonItem=BARBUTTON(@"Filps",@selector(filps:));

UISegmentedControl *ucl=[[UISegmentedControl alloc] initWithItems:[@"Left Right" componentsSeparatedByString:@" "]];

ucl.selectedSegmentIndex=0;

ucl.segmentedControlStyle=UISegmentedControlStyleBar;

self.navigationItem.titleView=ucl;

[ucl release];

UIImageView *view1=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"1.png"]];

view1.tag=998;

UIImageView *view2=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"2.png"]];

view2.tag=999;

//UIView *view1=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 350)];

//view1.tag=998;

//view1.backgroundColor=[UIColor redColor];

//UIView *view2=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 350)];

//view2.tag=999;

//view2.backgroundColor=[UIColor greenColor];

UIView *views=[[UIView alloc] initWithFrame:CGRectMake(0, 0, view1.frame.size.width, view1.frame.size.height)];

views.tag=100;

views.backgroundColor=[UIColor blackColor];

[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


热点排行