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];
}
会更加熟悉些。下面把代码贴出来学习学习。
- (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];
}
相关文章推荐
- ios 视图动画翻转效果
- ios常用16种视图切换动画效果
- 两个UIViewController之间的翻转可以用动画效果翻转(上下,左右)--跨界面之间的视图切换
- ios旋转视图 视图动画效果CGAffineTransformRotate
- iOS视图动画效果
- iOS视图弹出、平移、旋转、翻转、剪切等变换效果实现
- ios 视图切换动画效果
- IOS视图缩放显示动画效果
- iOS项目开发实战——视图动画效果
- iOS 视图控制器转场动画/页面切换效果/跳转动画 学习
- iOS开发笔记--视图切换的动画效果
- iOS 模态视图转场的动画效果
- iOS 比例 缩放视图 视图动画效果 CGAffineTransformMakeScale
- iOS高仿微信相册界面翻转过渡动画效果
- IOS视图切换动画效果<代码演示>
- iOS 动画效果弹出提示视图
- 仿iOS原生弹出视图效果的 HUD的弹出动画
- IOS视图控制器自定义动画效果
- iOS Controller中视图切换动画效果
- 【IOS动画】视图左右抖动动画效果