您的位置:首页 > 移动开发 > IOS开发

ios 视图动画翻转效果

2012-05-31 10:42 423 查看
虽然,网上有很多代码,但是 还是觉得自己写了一个简单的动画翻转的效果,

会更加熟悉些。下面把代码贴出来学习学习。

- (void)viewDidLoad {

[super viewDidLoad];

UIBarButtonItem *flipButton=[[UIBarButtonItem alloc]

initWithTitle:@"翻转"

style:UIBarButtonItemStyleBordered

target:self

action:@selector(flip:)];

self.navigationItem.rightBarButtonItem=flipButton;

fistView=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];

fistView.tag=100;

fistView.backgroundColor=[UIColor redColor];

[self.view addSubview:fistView];

secondView=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];

secondView.tag=101;

secondView.backgroundColor=[UIColor yellowColor];

[self.view addSubview:secondView];

}

-(void)flip:(id)sender{

CGContextRef context=UIGraphicsGetCurrentContext();

[UIView beginAnimations:nil context:context];

[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

[UIView setAnimationDuration:1.0];

[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES];

//这里时查找视图里的子视图(这种情况查找,可能时因为父视图里面不只两个视图)

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

NSInteger seconde= [[self.view subviews] indexOfObject:[self.view viewWithTag:101]];

[self.view exchangeSubviewAtIndex:fist withSubviewAtIndex:seconde];

//当父视图里面只有两个视图的时候,可以直接使用下面这段.

//[self.view exchangeSubviewAtIndex:0 withSubviewAtIndex:1];

[UIView setAnimationDelegate:self];

[UIView commitAnimations];

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: