读书人

交叉淡化、新视图移动到旧视图下新视

发布时间: 2012-08-02 11:35:26 作者: rapoo

交叉淡化、新视图移动到旧视图上,新视图推出就视图,旧视图移开显示新的

? ? //

// ?TestBedViewControler_004.m

// ?UIViewAnimationsTest

//

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

// ?Copyright 2011 __MyCompanyName__. All rights reserved.

//

?

#import "TestBedViewControler_004.h"

?

?

@implementation TestBedViewControler_004

?

/*

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

//Set up the animation

CATransition *animation=[CATransition animation];

animation.delegate=self;

animation.duration=1.0f;

animation.timingFunction=UIViewAnimationCurveEaseInOut;

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

case 0://交叉淡化过渡

animation.type=kCATransitionFade;

break;

case 1://新视图移动到旧视图上面,好像盖在上面

animation.type=kCATransitionMoveIn;

break;

case 2://新视图将旧视图推出去

animation.type=kCATransitionPush;

break;

case 3://将旧视图移开显示出下面的新视图

animation.type=kCATransitionReveal;

break;

default:

break;

}

if (isLeft) {

animation.subtype=kCATransitionFromRight;

}else {

animation.subtype=kCATransitionFromLeft;

}

//Perform the animation

NSInteger purple=[[self.view subviews] indexOfObject:[self.view viewWithTag:99]];

NSInteger white=[[self.view subviews] indexOfObject:[self.view viewWithTag:100]];

[self.view exchangeSubviewAtIndex:purple withSubviewAtIndex:white];

//[self.view addSubview:[self.view viewWithTag:100]];

[[self.view layer] addAnimation:animation forKey:@"animation"];

//Allow or disallow user interaction (otherwise you can touch "through" the cover view to enable/disable the switch)

if (purple<white) {

[self.view viewWithTag:99].userInteractionEnabled=YES;

}else {

[self.view viewWithTag:99].userInteractionEnabled=NO;

}

isLeft=!isLeft;

?

?

}

?

?

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

- (void)viewDidLoad {

? ? [super viewDidLoad];

self.navigationItem.rightBarButtonItem=BARBUTTON(@"Go",@selector(animate:));

UISegmentedControl *segmentedControl=[[UISegmentedControl alloc] initWithItems:[@"Fade Move Push Reveal" componentsSeparatedByString:@" "]];

segmentedControl.selectedSegmentIndex=0;

segmentedControl.segmentedControlStyle=UISegmentedControlStyleBar;

self.navigationItem.titleView=segmentedControl;

[segmentedControl release];

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

view1.tag=99;

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

view2.tag=100;

[self.view addSubview:view1];

[self.view addSubview:view2];

[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


读书人网 >行业软件

热点推荐