iOS-动画效果(图片左右滑动 添加动画效果)
来源:互联网 发布:not close json text 编辑:程序博客网 时间:2024/05/17 07:23
#import "ViewController.h"
#import "NextViewController.h"
typedef enum Direction{
Right = 0,
Left,
}Direction;
@interface ViewController ()
{
NSArray *imageList;
UIImageView *showImage;
int index;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
imageList = @[@"tianhe1.jpg",@"tianhe2.jpg",@"tianhe3.jpg"];
showImage = [[UIImageView alloc]initWithFrame:[UIScreen mainScreen].bounds];
showImage.image = [UIImage imageNamed:imageList[0]];
showImage.userInteractionEnabled = YES;
[self.view addSubview:showImage];
UISwipeGestureRecognizer *rightSWip = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(right)];
rightSWip.direction = UISwipeGestureRecognizerDirectionRight;
[self.view addGestureRecognizer:rightSWip];
UISwipeGestureRecognizer *leftSwip = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(left)];
leftSwip.direction = UISwipeGestureRecognizerDirectionLeft;
[self.view addGestureRecognizer:leftSwip];
UILongPressGestureRecognizer *next = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(next:)];
[self.view addGestureRecognizer:next];
}
- (void)left
{
[self changeImageWithDirection:Left];
}
- (void)right
{
[self changeImageWithDirection:Right];
}
- (void)changeImageWithDirection:(Direction)direction
{
index = direction == Right ? [self countRelease]:[self countAdd];
CATransition *transition = [CATransition animation];
transition.type = direction == Right ? kCATransitionFade:@"rippleEffect";
transition.subtype = direction == Right ? kCATransitionFromRight:kCATransitionFromLeft;
transition.duration = 1.5;
[showImage.layer addAnimation:transition forKey:imageList[index]];
showImage.image = [UIImage imageNamed:imageList[index]];
}
#pragma mark ------- 向左滑动图片自加++ ------
//需要通过方向判断是自加还是自减 把计算号的值 赋值给 全局变量index
- (int)countAdd
{
index ++;
//如果超出了 图片数组的元素个数 让index等于0(修复成0) 如果没有超出 返回自加之后的值
return index >= imageList.count ? 0:index;
}
#pragma mark ------- 向右滑动图片自加++ ------
- (int)countRelease
{
index --;
return index < 0 ? (int)imageList.count-1:index;
}
- iOS-动画效果(图片左右滑动 添加动画效果)
- 手机web图片左右滑动动画效果分享
- 【IOS动画】视图左右抖动动画效果
- IOS 图片动画效果
- IOS中多张图片动画效果
- ios实现图片动画效果
- android 滑动动画效果
- android之ViewFlipper实现左右滑动动画效果
- android之ViewFlipper实现左右滑动动画效果
- android之ViewFlipper实现左右滑动动画效果
- android之ViewFlipper实现左右滑动动画效果
- android之ViewFlipper实现左右滑动动画效果
- 带渐变层叠动画的左右滑动效果
- android之ViewFlipper实现左右滑动动画效果
- android之ViewFlipper实现左右滑动动画效果
- Jquery 动画效果 左右移动
- Android 图片左右滑动效果
- IOs-控件上添加动画效果
- 安卓开发真机调试中的问题
- 大数相加
- Java冒泡排序
- iOS开发常用网址
- 倒99表
- iOS-动画效果(图片左右滑动 添加动画效果)
- 静态链接库LIB和动态链接库DLL的区别
- Xcode 7遇到 App Transport Security has blocked a cleartext HTTP 错误
- Android手势判断
- 大数乘法
- 1/1+1/3+1/5+……+1/99的和
- tomcat环境变量配置
- 浅谈Android开放网络端口的安全风险
- myeclipse修改乱码(编码格式修改)