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

  • 相关阅读:
    华为服务器内存插法
    关于公司内部域名称是否要和外部真实域名称对应的问题
    配置Office 365单点登录摘要
    配置Office 365单点登录过程中的一些注意事项
    AADC安装指南
    使用非Web方式从CA申请证书
    爬取某招聘网站的信息
    通过PowerShell启用AADC的密码同步功能
    Azure Active Directory Connect密码同步问题
    Python脚本配合Linux计划任务工作
  • 原文地址:https://www.cnblogs.com/thbbsky/p/4333913.html
Copyright © 2011-2022 走看看