UIView动画

实现ios动画有两种方法:一种UIView层面的,一种是使用CATransition.

[objc] view plain copy 在CODE上查看代码片派生到我的代码片
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.

UIView *redView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];  
redView.backgroundColor = [UIColor redColor];  
[self.view addSubview:redView];  

UIView *yellowView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];  
yellowView.backgroundColor = [UIColor yellowColor];  
[self.view addSubview:yellowView];  

UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];  
[button setTitle:@"改变1" forState:UIControlStateNormal];  
button.frame = CGRectMake(10, 10, 300, 40);  
[button addTarget:self action:@selector(changeUIView1) forControlEvents:UIControlEventTouchUpInside];  
[self.view addSubview:button];  



UIButton *button2 = [UIButton buttonWithType:UIButtonTypeRoundedRect];  
[button2 setTitle:@"改变2" forState:UIControlStateNormal];  
button2.frame = CGRectMake(10, 120, 300, 40);  
[button2 addTarget:self action:@selector(changeUIView2) forControlEvents:UIControlEventTouchUpInside];  
[self.view addSubview:button2];  

}
-(void) changeUIView1{
[UIView beginAnimations:@”animation” context:nil];
[UIView setAnimationDuration:1.0f];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.view cache:YES];
[self.view exchangeSubviewAtIndex:1 withSubviewAtIndex:0 ];
[UIView commitAnimations];
}

-(void) changeUIView2{
CATransition *transition = [CATransition animation];
transition.delegate = self;
transition.duration = 2.0f;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
transition.type = kCATransitionPush;
transition.type = @”pageCurl” ;//另一种设置动画效果方法
transition.subtype = kCATransitionFromBottom;
[self.view exchangeSubviewAtIndex:1 withSubviewAtIndex:0];
[self.view.layer addAnimation:transition forKey:@”animation”];
}

调用CATransition需要在frameworks中添加QuartzCore.framework,在.h文件中加入 #import

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值