使用CATransition动画来进行图像翻转效果,实用性很强
来源:互联网 发布:淘宝购物车是什么意思 编辑:程序博客网 时间:2024/06/05 21:10
- (void)viewDidLoad {
[superviewDidLoad];
self.view.backgroundColor = [UIColorwhiteColor];
[selfcreateImageView];
[selfswipeGesture];
}
- (void)createImageView
{
UIImageView *imageView = [[UIImageViewalloc]initWithFrame:[[UIScreenmainScreen]bounds]];
imageView.image = [UIImageimageNamed:@"00.jpg"];
imageView.contentMode =UIViewContentModeScaleToFill;
self.imageView = imageView;
[self.viewaddSubview:self.imageView];
}
/**轻扫手势*/
- (void)swipeGesture
{
/**轻扫手势--左手势*/
UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizeralloc]initWithTarget:selfaction:@selector(swipeGestureOfLeftClicked:)];
/**手势方向*/
swipeLeft.direction =UISwipeGestureRecognizerDirectionLeft;
/**轻扫手势--右手势*/
UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizeralloc]initWithTarget:selfaction:@selector(swipeGestureOfRightClicked:)];
swipeRight.direction =UISwipeGestureRecognizerDirectionRight;
[self.viewaddGestureRecognizer:swipeLeft];
[self.viewaddGestureRecognizer:swipeRight];
}
#pragma mark --向左滑动浏览下一张图片--
- (void)swipeGestureOfLeftClicked:(UISwipeGestureRecognizer *)swipeGesture
{
/**左手势为YES*/
[selftransitionAnimation:YES];
}
#pragma mark --向右滑动浏览上一张图片--
- (void)swipeGestureOfRightClicked:(UISwipeGestureRecognizer *)swipeGesture
{
[selftransitionAnimation:NO];
}
- (void)transitionAnimation:(BOOL)isNext
{
//创建转场动画对象
CATransition *transition = [[CATransitionalloc]init];
/* The name of the transition. Current legal transition types include
* `fade', `moveIn', `push' and `reveal'. Defaults to `fade'. */
/**
* 1.#define定义的常量
kCATransitionFade 交叉淡化过渡 默认
kCATransitionMoveIn 新视图移到旧视图上面,覆盖原图
kCATransitionPush 新视图把旧视图推出去 ,推出
kCATransitionReveal 将旧视图移开,显示下面的新视图 ,从底部显示
2.用字符串表示
pageCurl 向上翻一页
pageUnCurl 向下翻一页
rippleEffect 滴水效果
suckEffect 收缩效果,如一块布被抽走
cube 立方体效果
oglFlip 上下翻转效果
注意:
还有很多私有API效果,使用的时候要小心,可能会导致app审核不被通过(悲剧啊,为啥有却不让用啊!好东西不应该被束之高阁!)
fade //交叉淡化过渡(不支持过渡方向)
push //新视图把旧视图推出去
moveIn //新视图移到旧视图上面
reveal //将旧视图移开,显示下面的新视图
cube //立方体翻滚效果
oglFlip //上下左右翻转效果
suckEffect //收缩效果,如一块布被抽走(不支持过渡方向)
rippleEffect //滴水效果(不支持过渡方向)
pageCurl //向上翻页效果
pageUnCurl //向下翻页效果
cameraIrisHollowOpen //相机镜头打开效果(不支持过渡方向)
cameraIrisHollowClose //相机镜头关上效果(不支持过渡方向)
*/
//设置动画类型,注意对于苹果官方没有公开的动画类型智能使用字符串,并没有对应的常量意义
// transaction.type=@"pageCurl";//控制图片的滑动类型
if (isNext ==YES) {
transition.type = @"puch";
transition.subtype = kCATransitionFromRight;
} else {
transition.type = @"cube";
transition.subtype = kCATransitionFromLeft;
}
//设置动画时长,默认为0
transition.duration=1.0;
/* The amount of progress through to the transition at which to begin
* and end execution. Legal values are numbers in the range [0,1].
* `endProgress' must be greater than or equal to `startProgress'.
* Default values are 0 and 1 respectively. */
//动画开始的进度
// transaction.startProgress=0.1;
//动画结束的进度,,,结束的进度必须大于开始的进度
// transaction.endProgress=0.5;
//动画的速度
// transaction.speed=100.0;
//设置转场后的新视图添加转场动画
self.imageView.image=[selftransitionImage:isNext];
//添加动画效果
[self.imageView.layeraddAnimation:transition forKey:@"Animation"];
}
- (UIImage *)transitionImage:(BOOL)isNext
{
if (isNext ==YES) {
self.currentIndex = (self.currentIndex + 1) % IMAGE_NUMBER;
} else {
self.currentIndex = (self.currentIndex - 1 + IMAGE_NUMBER) % IMAGE_NUMBER;
}
UIImage *image = [UIImageimageNamed:[NSStringstringWithFormat:@"0%ld.jpg",self.currentIndex]];
return image;
}
- 使用CATransition动画来进行图像翻转效果,实用性很强
- iOS动画效果 CATransition
- ios-day18-12(使用CATransition实现转场动画效果)
- 使用 Java 进行图像处理 - 图像翻转
- CATransition动画的使用
- ios 动画效果CATransition笔记
- ios 动画效果CATransition笔记
- IOS CATransition 立体动画效果
- CATransition动画的简单使用
- CATransition 简单使用(转场动画)
- Iphone翻页动画效果--CATransition实现
- CATransition完成几种动画效果
- CATransition完成几种动画效果
- 文字翻转动画效果
- 制作翻转效果动画
- Android3D动画翻转效果
- 硬币翻转动画效果
- Card翻转动画效果
- windows 命令符python3实现tab自动补全功能
- dubbo+zookeeper+dubbo管理控制台实践demo
- 对称加密和非对称加密总结
- HDU4009 Transfer water(最小树形图)
- RecordSortedList应用实例
- 使用CATransition动画来进行图像翻转效果,实用性很强
- java:java.util.Properties的便利性封装
- torch/caffe等框架下解决内存无法garbage collection的问题
- JOOQ 官网 3.8API
- UIScrollviewview上添加button不显示和button滑动超出范围问题
- OC Category 分类 Extension 延展.md
- MATLAB 内存不足 "Out of memory" 解决办法
- >>>,<< ,<< java中的三种移位运算符
- 面试题及答案