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 ...
随机推荐
- 每天php函数 - floatval() 获取变量的浮点值
float floatval ( mixed $var ) 返回变量 var的 float 数值. var 可以是任何标量类型.你不能将 floatval() 用于数组或对象. <?php$va ...
- PHP 错误与异常 笔记与总结(8)自定义错误处理函数 set_error_handler()
通过 Set_error_handler() 函数设置用户自定义的错误处理函数. 步骤: ① 创建错误处理函数 ② 设置不同级别调用函数 ③ Set_error_handler() 函数制定接管错误处 ...
- Javascript 笔记与总结(1-1)作用域
以语言的角度学习 Js 的底层原理(与 DOM 无关):① 作用域链 ② 词法分析 ③ 闭包 ④ 面向对象(原型链) ① 作用域链 例1 <script> var c = 5; funct ...
- PHP不仅仅是PHP
PHP不仅仅是PHP PHP不仅仅是PHP. PHP的面试不仅仅会问到PHP语言本身(基本都是基础和细节),下面列举的主要是都是高级工程师的要求 比如:PHP中include和require的区别 ...
- C++ 常用术语(后续补充)
内存对齐常量折叠 堆栈解退(stack unwinding) 模板特化模板偏特化 模板实例化 函数对象 单一定义规则(One-Definition Rule,ODR) 自引用 对象切片(objec ...
- 原创:CentOS6.4配置solr 4.7.2+IK分词器
本文原创,转载请注明出处 相关资源下载:http://pan.baidu.com/s/1pJPpiqv 1.首先说明一下 solr是java语言开发的企业级应用服务器,所以你首先安装好jdk,配置好j ...
- P1018 乘积最大
开始定义状态f[i][j][k]为[i,j)区间插入k个括号,使用记忆化搜索,但是成功爆栈,得到4个mle #include <bits/stdc++.h> using namespace ...
- mysql ERROR 1045 (28000): Access denied for user解决方法 (转)
问题重现(以下讨论范围仅限Windows环境): C:\AppServ\MySQL> mysql -u root -pEnter password:ERROR 1045 (28000): Acc ...
- GZip压缩的js文件IE6下面不能包含<script>标签
IE6下面,GZip压缩的js文件,如果js中包含<script>标签,一遇到这样的标签,后面的内容居然都截断了,狂晕! 花了我一个晚上来找原因.. 需要将字符串'<script&g ...
- [转]正则表达式相关:C# 抓取网页类(获取网页中所有信息)
using System; using System.Data; using System.Configuration; using System.Net; using System.IO; usin ...