iOS抽奖转盘动画之转场动画与动画组
2015-10-12 10:14
369 查看
将viewdidload里面的代码全部注释掉
- (void)viewDidLoad {
[superviewDidLoad];
}
重写点击交换的事件方法
//交换视图
- (IBAction)changeBtn {
//通过类方法来创建转场动画
CATransition *transition = [CATransitionanimation];
transition.duration =
1.0f;//动画的间隔为1S
//设置动画的变化方法
transition.timingFunction = [CAMediaTimingFunctionfunctionWithName:kCAMediaTimingFunctionEaseInEaseOut];
//下面是交换视图特有的属性
//私有API 使用私有API的时候要慎重(这个是苹果官网承认的)
transition.type =
@"pageCurl";
// transition.type =@"fade";fade渐隐
//type的子类型 转换的方向
transition.subtype =
@"fromRight";
// //这里也可以写成这样 效果是一样的
// transition.subtype = kCATransitionFromRight;
//设置具体的动画 交换两个视图的位置
[_aninmationViewexchangeSubviewAtIndex:0withSubviewAtIndex:1];
//给图层添加动画
[_aninmationView.layeraddAnimation:transitionforKey:@"myAnimation"];
}
这样运行出来的效果是 点击了交换按钮 出来动画翻页效果 但是始终展现的是最上面的view 并不会实现预期的交换两个view的效果
查看了一下这个函数的官方文档
- (void)addAnimation:(CAAnimation *)anim forKey:(nullableNSString *)key;
我们可以看到文档中是这么解释的:
/** Animation methods. **/
/* Attach an animation object to the layer. Typically this is implicitly
* invoked through an action that is an CAAnimation object.
*
* 'key' may be any string such that only one animation per unique key
* is added per layer. The special key 'transition' is automatically
* used for transition animations. The nil pointer is also a valid key.
*
* If the `duration' property of the animation is zero or negative it
* is given the default duration, either the value of the
* `animationDuration' transaction property or .25 seconds otherwise.
*
* The animation is copied before being added to the layer, so any
* subsequent modifications to `anim' will have no affect unless it is
* added to another layer. */
翻译过来就是:
/** Animation methods. **/ 动画方法
/* 给图层(layer)附加上一个动画对象 通常这是隐式的通过一个动作,这个动作是一个CAAnimation对象来调用.
* 'key'键可能是任意的string,这样每个唯一的键只有一个动画(animation)被添加到图层(layer)中.特殊的键'transition'会被自动用于转场动画中,空指针同样也是一个空的键值.
*如果动画的持续时间(duration)属性是0或者负,则给定默认时间,或者是转换属性`animationDuration'的值,否则的话0.25S.
* 动画(animation)被添加到图层(layer)之前已经被复制(copied),所以任何后续对'anim'动画修改都不会有影响,除非它被添加到另一个图层(layer)中 /*这句话有点郁闷 没怎么理解他说的意思*/
**/
组动画:
-(void)animationGroup{
CAAnimationGroup *animG = [CAAnimationGroup
animation];
//2.添加动画到动画数组animation groups中
animG.animations =
@[anim1,anim2];
//4.添加动画到图层上
[self.navigationController.view.layer
addAnimation:animG
forKey:@"animG"];
}
然后就会依次执行组动画里的动画了
- (void)viewDidLoad {
[superviewDidLoad];
}
重写点击交换的事件方法
//交换视图
- (IBAction)changeBtn {
//通过类方法来创建转场动画
CATransition *transition = [CATransitionanimation];
transition.duration =
1.0f;//动画的间隔为1S
//设置动画的变化方法
transition.timingFunction = [CAMediaTimingFunctionfunctionWithName:kCAMediaTimingFunctionEaseInEaseOut];
//下面是交换视图特有的属性
//私有API 使用私有API的时候要慎重(这个是苹果官网承认的)
transition.type =
@"pageCurl";
// transition.type =@"fade";fade渐隐
//type的子类型 转换的方向
transition.subtype =
@"fromRight";
// //这里也可以写成这样 效果是一样的
// transition.subtype = kCATransitionFromRight;
//设置具体的动画 交换两个视图的位置
[_aninmationViewexchangeSubviewAtIndex:0withSubviewAtIndex:1];
//给图层添加动画
[_aninmationView.layeraddAnimation:transitionforKey:@"myAnimation"];
}
这样运行出来的效果是 点击了交换按钮 出来动画翻页效果 但是始终展现的是最上面的view 并不会实现预期的交换两个view的效果
查看了一下这个函数的官方文档
- (void)addAnimation:(CAAnimation *)anim forKey:(nullableNSString *)key;
我们可以看到文档中是这么解释的:
/** Animation methods. **/
/* Attach an animation object to the layer. Typically this is implicitly
* invoked through an action that is an CAAnimation object.
*
* 'key' may be any string such that only one animation per unique key
* is added per layer. The special key 'transition' is automatically
* used for transition animations. The nil pointer is also a valid key.
*
* If the `duration' property of the animation is zero or negative it
* is given the default duration, either the value of the
* `animationDuration' transaction property or .25 seconds otherwise.
*
* The animation is copied before being added to the layer, so any
* subsequent modifications to `anim' will have no affect unless it is
* added to another layer. */
翻译过来就是:
/** Animation methods. **/ 动画方法
/* 给图层(layer)附加上一个动画对象 通常这是隐式的通过一个动作,这个动作是一个CAAnimation对象来调用.
* 'key'键可能是任意的string,这样每个唯一的键只有一个动画(animation)被添加到图层(layer)中.特殊的键'transition'会被自动用于转场动画中,空指针同样也是一个空的键值.
*如果动画的持续时间(duration)属性是0或者负,则给定默认时间,或者是转换属性`animationDuration'的值,否则的话0.25S.
* 动画(animation)被添加到图层(layer)之前已经被复制(copied),所以任何后续对'anim'动画修改都不会有影响,除非它被添加到另一个图层(layer)中 /*这句话有点郁闷 没怎么理解他说的意思*/
**/
组动画:
-(void)animationGroup{
CAAnimationGroup *animG = [CAAnimationGroup
animation];
//2.添加动画到动画数组animation groups中
animG.animations =
@[anim1,anim2];
//4.添加动画到图层上
[self.navigationController.view.layer
addAnimation:animG
forKey:@"animG"];
}
然后就会依次执行组动画里的动画了
相关文章推荐
- iOS 9 适配系列教程
- iOS xib布局小技巧-边框设置
- iOS 拷贝、剪切和粘贴理论基础(转)
- iOS图片占内存过大的问题完美解决
- 本地推送。启动画面的设置(iOS)
- xcode7 ios9遇到的几个坑
- iOS 统计项目的总行数
- IOS之NSFileManager 和NSFileHandle
- IOS工程中如何去掉第三方的警告
- iOS9适配+warning消除
- ios获取系统时间
- iOS删除本地文件
- ios 下创建,删除文件夹的方法
- iOS 不规则的ImageView
- iOS图片内存优化
- iOS开发笔记--ios 画图总结
- iOS scrollView循环自动滚动
- iOS开发——高级篇——远程音频、视频播放
- iOS界面响应式布局方式对比
- 蓝懿iOS 内容和心得