#import <UIKit/UIKit.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;

@end
#import "AppDelegate.h"
#import "RootViewController.h" @interface AppDelegate () @end @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor]; self.window.rootViewController = [[RootViewController alloc] init]; [self.window makeKeyAndVisible];
return YES;
} @end
#import <UIKit/UIKit.h>

@interface RootViewController : UIViewController

@end
#import "RootViewController.h"
#define ImageCount 5
@interface RootViewController ()
{
UIImageView *_imageView;
int currentIndex;
}
@end @implementation RootViewController - (void)viewDidLoad {
[super viewDidLoad];
// 定义图片控件
_imageView = [[UIImageView alloc] init];
_imageView.frame = [UIScreen mainScreen].bounds;
_imageView.contentMode = UIViewContentModeScaleAspectFit;
_imageView.image = [UIImage imageNamed:@"0.jpg"];
_imageView.userInteractionEnabled = YES;
[self.view addSubview:_imageView];
// 添加手势
UISwipeGestureRecognizer *leftSwipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(leftSwipeAction:)];
leftSwipe.direction = UISwipeGestureRecognizerDirectionLeft;
[_imageView addGestureRecognizer:leftSwipe]; UISwipeGestureRecognizer *rightSwipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(rightSwipeAction:)];
rightSwipe.direction = UISwipeGestureRecognizerDirectionRight;
[_imageView addGestureRecognizer:rightSwipe]; }
#pragma mark --向左滑动浏览下一张图片--
- (void)leftSwipeAction:(UISwipeGestureRecognizer *)sender{
[self transitionAnimation:YES];
} #pragma mark --向右滑动浏览上一张图片--
- (void)rightSwipeAction:(UISwipeGestureRecognizer *)sender{
[self transitionAnimation:NO];
} #pragma mark --旋转动画--
- (void)transitionAnimation:(BOOL)isLeft{
//创建转场动画对象
CATransition *transition = [[CATransition alloc] init];
//设置动画类型,注意对于苹果官方没公开的动画类型只能使用字符串,并没有对应的常量定义
transition.type = @"cube";
//设置子类型
if (isLeft) {
transition.subtype = kCATransitionFromRight;
}else{
transition.subtype = kCATransitionFromLeft;
}
//设置动画时常
transition.duration = 0.8;
//设置转场后的新视图添加转场动画
_imageView.image = [self getImageByIndex:isLeft];
[_imageView.layer addAnimation:transition forKey:@"KCTransitionAnimation"];
} #pragma mark --获取相应的图片--
- (UIImage *)getImageByIndex:(BOOL)isLeft{
if (isLeft) {
currentIndex = (currentIndex + ) % ImageCount;
}else{
currentIndex = (currentIndex - + ImageCount) % ImageCount;
}
NSString *imageName = [NSString stringWithFormat:@"%i.jpg",currentIndex];
return [UIImage imageNamed:imageName];
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end

iOS 图片循环滚动(切片效果)的更多相关文章

  1. 特殊例子--JavaScript代码实现图片循环滚动效果

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  2. 使用UIScrollView 结合 UIImageView 实现图片循环滚动

    场景: 在开发工作中,有时我们需要实现一组图片循环滚动的情况.当我们使用 UIScrollView 结合 UIImageView 来实现时,一般 UIImageView 会尽量考虑重用,下面例子是以( ...

  3. cocos2d(背景图片循环滚动)

    背景图片循环滚动 使用action 实现的: 主要有两个背景图片交替循环滚动:我选的两个背景图片的宽度都是1024的 ,所以定义了#define BGIMG_WIDTH 1024 代码如下: 在Hel ...

  4. 基于html5可拖拽图片循环滚动切换

    分享一款基于html5可拖拽图片循环滚动切换.这是一款支持手机端拖拽切换的网站图片循环滚动特效.效果图如下: 在线预览   源码下载 实现的代码. html代码: <div id="s ...

  5. 图片循环滚动效果shader

    背景无限循环滚动效果,有X和Y轴的速度控制,方便控制.见下图,操作步骤同之前的背景循环设置. shader如下: Shader "Custom/Scroll" { Properti ...

  6. iOS无限循环滚动scrollview

    经常有园友会问"博主,有没有图片无限滚动的Demo呀?", 正儿八经的图片滚动的Demo我这儿还真没有,今天呢就封装一个可以在项目中直接使用的图片轮播.没看过其他iOS图片无限轮播 ...

  7. iOS开发 - 循环滚动的ScrollView

    源码在这里,请多多指教. 由于开发需要,要用到循环自动滚动的scrollView,借鉴了前人的思路,重新设计了一个AutoSlideScrollView.先自吹自擂一翻吧: 借鉴UITableView ...

  8. php广告图片循环播放 幻灯片效果

    <!DOCTYPE> <html> <head> <meta http-equiv="content-type" content=&quo ...

  9. UIScrollView 图片循环滚动

    1:假如有6个图片:那个,Scrollview的大小加 7 个图片的大小 2: //ImageScrollView; UIScrollView *imageScroll = [[UIScrollVie ...

随机推荐

  1. 在Windows下部署安装hexo

    由于hexo的文档里并没有一步步详细写出过程的细节,在Windows下又更麻烦,所以就很容易入坑. 安装 安装github for windows,msysgit 安装包: https://githu ...

  2. visual 2008中error PRJ0003 : 生成 cmd.exe 时出错

    visual 2008中error PRJ0003 : 生成 cmd.exe 时出错”,   和vs2008 sp1没关系 解决方案:工具—>选项—>项目和解决方案—>VC++目录, ...

  3. Apache Spark源码走读之6 -- 存储子系统分析

    欢迎转载,转载请注明出处,徽沪一郎. 楔子 Spark计算速度远胜于Hadoop的原因之一就在于中间结果是缓存在内存而不是直接写入到disk,本文尝试分析Spark中存储子系统的构成,并以数据写入和数 ...

  4. 设计模式学习系列9 外观模式Facade

    1.概述 自己卖了一辆越野自行车,但毕竟不是自己定制的,买回来之后可能需要更改一下脚蹬,座皮,里程计数器或者刹车系统,假如将自行车看做一个整体系统,对我们而言使用的是自行车,然后我们对自己车构件的修改 ...

  5. BAT批处理(二)

    在前一篇中已对BAT批处理基础作了一些总结,但是对于BAT批处理还有很多的知识点没有讲解到,比如DOS中的特殊符号:IF.FOR的使用:变量:更多的DOS命令等等.本文在前一篇的基础上继续对BAT批处 ...

  6. jboss4.2.3建立oracle JMS应用

    一.基本配置 1 增加oracle驱动文件,ojdbc6.jar,不能使用小于该版本的jdbc驱动,jboss-4.2.3.GA\server\default\lib 2 增加retrotransla ...

  7. nrf51822裸机教程-GPIO

    首先看看一下相关的寄存器说明 Out寄存器 输出设置寄存器 每个比特按顺序对应每个引脚,bit0对应的就是 引脚0 该寄存器用来设置 引脚作为输出的时候的 输出电平为高还是低. 与输出设置相关的 还有 ...

  8. Android高级之Dalvik初识

    本文来自http://blog.csdn.net/liuxian13183/ ,引用必须注明出处! 研究安卓已多年,一直在应用层做开发,Framework层只是看过,也就是大家常说的"底层& ...

  9. Erlang ERTS的Trap机制的设计及其用途

    出处:http://mryufeng.iteye.com/blog/334744 erlang的trap机制在实现中用的很多,在费时的BIF操作中基本上都可以看到.它的实现需要erl vm的配合.它的 ...

  10. android jdbc 远程数据库

    http://blog.csdn.net/conowen/article/details/7435231/