实现动画
实现变淡(也就是变透明)然后在变回来
实例代码:
- (IBAction) doOpacity:(id) sender {
CABasicAnimation *animation = [CABasicAnimationanimationWithKeyPath:@"opacity"];
[animationsetDuration:2.0];
[animationsetRepeatCount:0];
[animationsetAutoreverses:YES];
[animationsetFromValue:[NSNumber numberWithFloat:1.0]];
//[animationsetByValue:[NSNumber numberWithFloat:0.5]];
[animationsetToValue:[NSNumber numberWithFloat:0]];
[animationsetDelegate:self];//optional
[_bookView.layer addAnimation:animationforKey:@"BookView-Opacity"];
//4.0新引入的方法^后面跟的是一个block,里面是你要写的所有语句
//
[UIViewanimateWithDuration:2.0
//
animations:^{[_bookView setAlpha:0];}
//传入一个叫finished参数,判断是否完成之前的动画
//
completion:^(BOOL finished){
//
[UIView animateWithDuration:2.0animations:^{[_bookView setAlpha:1.0];}];}];
}
动画知识补充:
一 动画代码过程:
二 不同对象调用动画
一 。
在动画中一般设置动画开始
[UIView beginAnimations:@"" context:nil];
当然在动画开始之前还可以做一些事
通过后边的那个参数content,但是我们这里就不做了
之后就是
1设置 动画时间
2设置 动画过程的类型 (说的是 :动画从开始如何 结束减速如何中间过度是否以下过度;系统定义有相关的类型 )
3设置 动画循环次数
4设置 动画类型(如是设置向上翻页 还是向下翻页 还是左转翻页。。。。)
在这个里 可能屏幕上有很多按钮 你选择一个按钮就对应一个类型
我们可以用按钮的tag来对应一种类型,
代码如下:
UIButton *theButton = (UIButton *)sender;//sender就是指的是所选的按钮。
switch(theButton.tag) {
case0:
[UIViewsetAnimationTransition:UIViewAnimationTransitio
nFlipFromLeftforView:self.view cache:YES];//oglFlip, fromLeft
break;
case1:
[UIViewsetAnimationTransition:UIViewAnimationTransitio
nFlipFromRightforView:self.view cache:YES];//oglFlip, fromRight
break;
case2:
[UIViewsetAnimationTransition:UIViewAnimationTransitio
nCurlUpforView:self.view cache:YES];
break;
case3:
[UIViewsetAnimationTransition:UIViewAnimationTransitio
nCurlDownforView:self.view cache:YES];
break;
default:
break;
二。
调用动画的view 常用分两种情况:
(1) 整个视图都要实现动画效果:
我们可以在控制器里边添加多个视图,
我们通过[self.view exchangeSubviewAtIndex:1withSubviewAtIndex:0];
来实现
(2) 如果只是视图的一部分 那么我们只需在动作事件函数中 给first' owner 添加一个动画
代码如下:
[animation setDelegate:self];//optional
[_bookView.layer addAnimation:animationforKey:@"BookView-Opacity"];
在我们的动画类型中 不是只有4种基础的类型
其他也有其他类型的动画
只是在国内我们没有经常用到
参考文献http://www.iphonedevwiki.net/index.php?title=UIViewAnimationState
这上边 会帮你了解很多 你文档看不到的动画。。。。
如
单个代码的实例:
- (IBAction)doPrivateCATransition:(id)sender{
NSLog(@"doUIViewAnimation2");
CATransition*animation = [CATransition animation];
animation.delegate = self;
animation.duration = 0.5f * slider.value;
animation.timingFunction = UIViewAnimationCurveEase
InOut;
animation.fillMode = kCAFillModeForwards;
animation.endProgress = slider.value;
animation.removedOnCompletion = NO;
UIButton*theButton = (UIButton *)sender;
switch(theButton.tag) {
case0:
animation.type = @"cube";//---
break;
case1:
animation.type = @"suckEffect";//103
break;
case2:
animation.type = @"oglFlip";//When subType is "fromLeft" or"fromRight", it's the official one.
break;
case3:
animation.type = @"rippleEffect";//110
break;
case4:
animation.type = @"pageCurl";//101
break;
case5:
animation.type = @"pageUnCurl";//102
break;
case6:
animation.type = @"rippleEffect";//107
break;
case7:
animation.type = @"cameraIrisHollowClose ";//106
break;
default:
break;
}
[self.view.layer addAnimation:animation forKey:@"animation"];
self.lastAnimation = animation;
if(slider.value == 1)
[self.viewexchangeSubviewAtIndex:1 withSubviewAtIndex:0];//Just remove, notrelease or dealloc
else{
for (int i =0; i < [self.view.subviews count]; i++) {
[[self.view.subviews objectAtIndex:i]setUserInteractionEnable
d:NO];
}
isHalfAnimation = YES;
}
}
实例代码:
- (IBAction) doOpacity:(id) sender {
//
//
//
//
}
动画知识补充:
一
二
一 。
在动画中一般设置动画开始
[UIView beginAnimations:@"" context:nil];
当然在动画开始之前还可以做一些事
之后就是
1设置 动画时间
2设置 动画过程的类型
3设置 动画循环次数
4设置
代码如下:
UIButton *theButton = (UIButton *)sender;//sender就是指的是所选的按钮。
二。
调用动画的view
(1) 整个视图都要实现动画效果:
(2) 如果只是视图的一部分 那么我们只需在动作事件函数中 给first' owner 添加一个动画
在我们的动画类型中
参考文献http://www.iphonedevwiki.net/index.php?title=UIViewAnimationState
这上边 会帮你了解很多 你文档看不到的动画。。。。
如
单个代码的实例:
- (IBAction)doPrivateCATransition:(id)sender{
}