iOS 图片循环滚动(切片效果)
#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 图片循环滚动(切片效果)的更多相关文章
- 特殊例子--JavaScript代码实现图片循环滚动效果
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 使用UIScrollView 结合 UIImageView 实现图片循环滚动
场景: 在开发工作中,有时我们需要实现一组图片循环滚动的情况.当我们使用 UIScrollView 结合 UIImageView 来实现时,一般 UIImageView 会尽量考虑重用,下面例子是以( ...
- cocos2d(背景图片循环滚动)
背景图片循环滚动 使用action 实现的: 主要有两个背景图片交替循环滚动:我选的两个背景图片的宽度都是1024的 ,所以定义了#define BGIMG_WIDTH 1024 代码如下: 在Hel ...
- 基于html5可拖拽图片循环滚动切换
分享一款基于html5可拖拽图片循环滚动切换.这是一款支持手机端拖拽切换的网站图片循环滚动特效.效果图如下: 在线预览 源码下载 实现的代码. html代码: <div id="s ...
- 图片循环滚动效果shader
背景无限循环滚动效果,有X和Y轴的速度控制,方便控制.见下图,操作步骤同之前的背景循环设置. shader如下: Shader "Custom/Scroll" { Properti ...
- iOS无限循环滚动scrollview
经常有园友会问"博主,有没有图片无限滚动的Demo呀?", 正儿八经的图片滚动的Demo我这儿还真没有,今天呢就封装一个可以在项目中直接使用的图片轮播.没看过其他iOS图片无限轮播 ...
- iOS开发 - 循环滚动的ScrollView
源码在这里,请多多指教. 由于开发需要,要用到循环自动滚动的scrollView,借鉴了前人的思路,重新设计了一个AutoSlideScrollView.先自吹自擂一翻吧: 借鉴UITableView ...
- php广告图片循环播放 幻灯片效果
<!DOCTYPE> <html> <head> <meta http-equiv="content-type" content=&quo ...
- UIScrollView 图片循环滚动
1:假如有6个图片:那个,Scrollview的大小加 7 个图片的大小 2: //ImageScrollView; UIScrollView *imageScroll = [[UIScrollVie ...
随机推荐
- Java SSH库使用简介:Apache sshd和JSch(Java Secure Channel)
1.Apache sshd Apache sshd是一个SSH协议的100%纯Java库,支持客户端和服务器.sshd库基于Apache MINA项目(可伸缩高性能的异步IO库). 官方网站:http ...
- Rails--%w用法[转]
%Q 用于替代双引号的字符串. 当你需要在字符串里放入很多引号时候, 可以直接用下面方法而不需要在引号前逐个添加反斜杠 (\") >> %Q(Joe said: "Fr ...
- 怎么样打印加密PDF文件
自然是解密后再打印.解密的方法,在linux下执行: pdf2ps xxx.pdf ps2pdf xxx.ps 参考资料 http://www.cyberciti.biz/faq/removing-p ...
- github 有名的问题【ERROR: Permission to .git denied to user】
小乌龙 以前一直是单兵做战,所以github repo对于我而言,只是一个存放.同步.备份代码的地方,协同作用完全没有体现出来. 最近跟朋友一起开发一个项目,他在github建了个公共的repo,我正 ...
- LR中的C语言问题
今天在调试LR的脚本(C)时遇到了几个甚是头痛得问题,下面简单总结下: 1.首先LR中的C编译器遵循C90标准,规定在一个函数中,变量定义必须放在所有的执行语句之前!一旦在运行语句之间再有定义的话,会 ...
- matches field ID value 17.9.1 The LABEL element
https://www.w3.org/TR/html401/interact/forms.html#edef-LABEL <!ELEMENT LABEL - - (%inline;)* -(LA ...
- 【转】Java 5种字符串拼接方式性能比较。
最近写一个东东,可能会考虑到字符串拼接,想了几种方法,但对性能未知,于是用Junit写了个单元测试. 代码如下: import java.util.ArrayList; import java.uti ...
- MvcPager分页控件的使用
1.引入MvcPager.dll(MvcPager分页控件:http://www.webdiyer.com/mvcpager/) 2.后台C# Controller: //Ddemo使用Webdiye ...
- Java实验报告五:Java网络编程及安全
Java实验报告五:Java网络编程及安全 ...
- Java回调实现
一.回调的形式 1. C.C++和Pascal允许将函数指针作为参数传递给其它函数.JavaScript,Python,和PHP允许简单的将函数名作为参数传递. 2. .NET Framework的语 ...