博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
通过左右手势实现简单的照片翻页功能
阅读量:5076 次
发布时间:2019-06-12

本文共 2481 字,大约阅读时间需要 8 分钟。

首先在加载UI的时候添加左右手势

//添加向右滑动的手势

 UISwipeGestureRecognizer *Recognizer;

    Recognizer = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(hanleSwipAction:)];
    [Recognizer setDirection:UISwipeGestureRecognizerDirectionRight];

//添加向左滑动的手势

    [self.view addGestureRecognizer:Recognizer];
    Recognizer = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(hanleSwipAction:)];
    [Recognizer setDirection:UISwipeGestureRecognizerDirectionLeft];
    [self.view addGestureRecognizer:Recognizer];
    

//滑动手势执行的动作(这里的数组模型是通过collectionView的item点击事件传入的)

-(void)hanleSwipAction:(UISwipeGestureRecognizer *)recognizer{
    if (recognizer.direction == UISwipeGestureRecognizerDirectionRight) {
        NSLog(@"向右滑动");
        if (self.curruntCount > 0) {
            self.curruntCount = self.curruntCount - 1;
            ExpertDetailPhoto *model = self.icons[self.curruntCount];
             self.pageNumLabel.text = [NSString stringWithFormat:@"%d/%lu",self.curruntCount + 1,(unsigned long)self.icons.count];
            [self.photoImageView sd_setImageWithURL:[NSURL URLWithString:model.img] placeholderImage:[UIImage imageNamed:@"ImageDefault"]];
            NSString *subtypeString;
            subtypeString = kCATransitionFromLeft;
           [self transitionWithType:@"pageCurl" WithSubtype:subtypeString ForView:self.view];
        }else{
            self.curruntCount = 0;
        }
    }else if(recognizer.direction == UISwipeGestureRecognizerDirectionLeft){
        NSLog(@"向左滑动");
        if (self.curruntCount < (int)(self.icons.count -1)) {
            self.curruntCount = self.curruntCount + 1;
            ExpertDetailPhoto *model = self.icons[self.curruntCount];
             self.pageNumLabel.text = [NSString stringWithFormat:@"%d/%lu",self.curruntCount + 1,(unsigned long)self.icons.count];
            [self.photoImageView sd_setImageWithURL:[NSURL URLWithString:model.img] placeholderImage:[UIImage imageNamed:@"ImageDefault"]];
            NSString *subtypeString;
            subtypeString = kCATransitionFromRight;
            [self transitionWithType:@"pageCurl" WithSubtype:subtypeString ForView:self.view];
        }else{
            self.curruntCount =(int)(self.icons.count - 1);
        }
    }
}

//执行动画的方法

- (void) transitionWithType:(NSString *) type WithSubtype:(NSString *) subtype ForView : (UIView *) view {

//实例化动画对象

    CATransition *animation = [CATransition animation];

//动画执行时间

    animation.duration = 0.5f;

//动画类型

    animation.type = type;
    if (subtype != nil) {
        animation.subtype = subtype;
    }

//动画执行过程效果(例:如淡进淡出)

    animation.timingFunction = UIViewAnimationOptionCurveEaseInOut;

//执行动画操作

    [view.layer addAnimation:animation forKey:@"animation"];

//view的layer层动画.

}

转载于:https://www.cnblogs.com/crazyfish520/p/5741652.html

你可能感兴趣的文章
PHP count down
查看>>
JVM参数调优:Eclipse启动实践
查看>>
(旧笔记搬家)struts.xml中单独页面跳转的配置
查看>>
不定期周末福利:数据结构与算法学习书单
查看>>
strlen函数
查看>>
python的列表与shell的数组
查看>>
关于TFS2010使用常见问题
查看>>
软件工程团队作业3
查看>>
python标准库——queue模块 的queue类(单向队列)
查看>>
火狐、谷歌、IE关于document.body.scrollTop和document.documentElement.scrollTop 以及值为0的问题...
查看>>
深入理解JVM读书笔记--字节码执行引擎
查看>>
vue-搜索功能-实时监听搜索框的输入,N毫秒请求一次数据
查看>>
批处理 windows 服务的安装与卸载
查看>>
React文档翻译 (快速入门)
查看>>
nodejs fs路径
查看>>
动态规划算法之最大子段和
查看>>
linux c:关联变量的双for循环
查看>>
深入浅出理解zend framework(三)
查看>>
python语句----->if语句,while语句,for循环
查看>>
javascript之数组操作
查看>>