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

  • 相关阅读:
    Java的基本数据类型
    第五小组链表讨论作业
    WLST 命令和变量
    Linux之find命令详解
    Linux之netstat命令详解
    Linux之 sort,uniq,cut,wc命令详解
    Linux之grep命令详解
    Linux之awk命令详解
    Linux之sed命令详解
    关于表 datatable的条件查询
  • 原文地址:https://www.cnblogs.com/thbbsky/p/4333913.html
Copyright © 2011-2022 走看看