zoukankan      html  css  js  c++  java
  • UIScrollView做循环图片

    #import "ViewController.h"
    #define IMAGE_COUNT 6
    @interface ViewController ()
    {
        UIImageView *myImageView;
        int currentIndex;
    
    }
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        myImageView=[[UIImageView alloc]init];
        myImageView.frame=[UIScreen mainScreen].applicationFrame;
        myImageView.contentMode=UIViewContentModeScaleAspectFit;
        myImageView.image=[UIImage imageNamed:@"1"];
        [self.view addSubview:myImageView];
        
        UISwipeGestureRecognizer *leftGesture=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(leftSwipe:)];
        leftGesture.direction=UISwipeGestureRecognizerDirectionLeft;
        [self.view addGestureRecognizer:leftGesture];
        
        UISwipeGestureRecognizer *rightGesture=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(rightSwipe:)];
        leftGesture.direction=UISwipeGestureRecognizerDirectionLeft;
        [self.view addGestureRecognizer:rightGesture];
        
    }
    
    -(void)leftSwipe:(UISwipeGestureRecognizer *)gesture
    {
        [self transitionAnimation:YES];
    
    }
    -(void)rightSwipe:(UISwipeGestureRecognizer *)gesture
    {
        [self transitionAnimation:NO];
        
    }
    -(void)transitionAnimation:(BOOL)isNext
    {
        CATransition *transition=[[CATransition alloc]init];
        transition.type=@"cube";
        if (isNext) {
            transition.subtype=kCATransitionFromRight;
        }
        else
        {
            transition.subtype=kCATransitionFromLeft;
        }
        transition.duration=2.0f;
        myImageView.image=[self getImage:isNext];
        [myImageView.layer addAnimation:transition forKey:@"KCTransitionAnimation"];
    }
    -(UIImage *)getImage:(BOOL)isNext
    {
       if(isNext)
       {
           currentIndex=(currentIndex+1)%IMAGE_COUNT;
       }
       else
       {
           currentIndex=(currentIndex-1+IMAGE_COUNT)%IMAGE_COUNT;
       }
        NSString *imageName=[NSString stringWithFormat:@"%d",currentIndex];
        return [UIImage imageNamed:imageName];
    }
    
    
    
    
    - (void)didReceiveMemoryWarning
    {
        [super didReceiveMemoryWarning];
        
    }
    
    @end

  • 相关阅读:
    centos7下redis6的安装
    Centos MySQL 5.7安装、升级教程
    Python之SSH-paramiko模块的使用
    Linux进程管理工具之Supervisor的使用
    Python-RPC框架之-ZeroRPC和SimpleXMLRPCServer
    Django入门--简单的form验证
    redis常用指令
    MySQL自增主键ID重新排序
    批量微博删除脚本
    解决springboot2.x集成redis节点故障redisTemplate报错redis Command timed out
  • 原文地址:https://www.cnblogs.com/thbbsky/p/4333913.html
Copyright © 2011-2022 走看看