OC基础之推荐一个旋转木马(跑马灯)效果的图片展示Demo
这个旋转木马(跑马灯)效果的图片展示Demo,包括设定旋转方向,图片倒影,背景设置,旋转速度,开始结束,点击显示选中的图片,彩色的块展示等等功能
效果图:(源码下载:https://github.com/hbblzjy/OC-CarrouselDemo)
部分代码展示:
- (void)testCarrouselView
{
NSMutableArray *array = [NSMutableArray array];
for (NSInteger i = 0; i < 8; i ++)
{
UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"mm%ld.jpeg", (long)i]];
[array addObject:image];
}
LYCarrouselView *carr = [[LYCarrouselView alloc] initWithFrame:CGRectMake(20, 80, 280, 160) images:array callback:^(NSInteger index, NSInteger event) {
NSLog(@"%ld %@", index, event == 1 ? @"点击" : @"长按");
}];
[carr addImage:[UIImage imageNamed:@"mm8.jpeg"]];
carr.backgroundColor = [UIColor blackColor];
carr.animationSpeed = 2;
carr.showReflectLayer = YES;
[self.view addSubview:carr];
UIButton *start = [UIButton buttonWithType:UIButtonTypeCustom];
[start setFrame:CGRectMake(40, 260, 100, 48)];
[start setTitle:@"开始" forState:UIControlStateNormal];
[start setBackgroundColor:[UIColor blueColor]];
[start handleControlEvents:UIControlEventTouchUpInside withBlock:^(UIControlEvents events) {
//默认为向左,如果暂停了,修改方向,开始向右
[carr startRotateRight:YES];
}];
[self.view addSubview:start];
UIButton *stop = [UIButton buttonWithType:UIButtonTypeCustom];
[stop setFrame:CGRectMake(180, 260, 100, 48)];
[stop setTitle:@"停止" forState:UIControlStateNormal];
[stop setBackgroundColor:[UIColor blueColor]];
[stop handleControlEvents:UIControlEventTouchUpInside withBlock:^(UIControlEvents events) {
[carr stopRotate];
}];
[self.view addSubview:stop];
LYSlider *slopex = [[LYSlider alloc] initWithWidth:280 center:CGPointMake(self.view.bounds.size.width / 2, self.view.bounds.size.height - 120) horizontal:YES];
[self.view addSubview:slopex];
slopex.thumbcolor = [UIColor magentaColor];
slopex.gradientBackInfo = [self sliderBackGraidentInfo];
slopex.value = 2 / 6.0;
[slopex handleSliderAction:UIControlEventValueChanged callback:^(LYSlider *slider, UIControlEvents event) {
carr.animationSpeed = slider.value * 6;
}];
}
视图.h文件内容:
- (NSDictionary *)sliderBackGraidentInfo
{
return @{@"locations" : @[@(0),
@(60 / 360.),
@(120 / 360.),
@(180 / 360.),
@(240 / 360.),
@(300 / 360.),
@(1)],
@"colors" : @[[UIColor redColor],
[UIColor yellowColor],
[UIColor greenColor],
[UIColor cyanColor],
[UIColor blueColor],
[UIColor magentaColor],
[UIColor redColor]]};
}
// index: view/image tag; event:(1 tap, 2 long press)
typedef void(^CarrouselBlock)(NSInteger index, NSInteger event);
// 旋转木马
@interface LYCarrouselView : UIView
@property (nonatomic, assign) BOOL canAutoRotate;// 自动动画开关
@property (nonatomic, assign) CGFloat sensitivity;// 滑动灵敏度 默认为1 越大越灵敏 0无效 正负影响方向
@property (nonatomic, assign) NSTimeInterval minimumPressTime;// 长按最短时间 超过则视为长按 默认为0.4
@property (nonatomic, assign) CGFloat animationSpeed;//默认为3.0 转过一张图时间
@property (nonatomic, assign) BOOL showReflectLayer;//是否显示倒影层
- (LYCarrouselView *)initWithFrame:(CGRect)frame images:(NSArray *)images callback:(CarrouselBlock)block;
- (void)addImage:(UIImage *)image;
- (void)startRotateRight:(BOOL)right; // 开始动画 (right:是否向右) canAutoRotate=YES
- (void)stopRotate; //停止动画 canAutoRotate=NO
OC基础之推荐一个旋转木马(跑马灯)效果的图片展示Demo的更多相关文章
- JS写一个列表跑马灯效果--基于touchslide.js
先放上效果图: 类似于这样的,在列表中循环添加背景样式的跑马灯效果. 准备引入JS插件: <script type="text/javascript" src="x ...
- jQuery 3D canvas 旋转木马(跑马灯)效果插件 - cloud carousel
插件名称-cloud carousel 最新版本-1.0.5 支持ie6-ie9,firefox,chrome,opera,safari等 1.引入jquery1.4.2.js 和CloudCarou ...
- flex 简单跑马灯效果(竖着显示)
<mx:Move id="move_area" target="{VBox_AreaWarning}"/> //move效果,模拟跑马灯 <s ...
- Android学习总结——TextView跑马灯效果
Android系统中TextView实现跑马灯效果,必须具备以下几个条件: 1.android:ellipsize="marquee" 2.TextView必须单行显示,即内容必须 ...
- 【Android】TextView跑马灯效果
老规矩,先上图看效果. 说明 TextView的跑马灯效果也就是指当你只想让TextView单行显示,可是文本内容却又超过一行时,自动从左往右慢慢滑动显示的效果就叫跑马灯效果. 其实,TextView ...
- Android界面(1) 使用TextView实现跑马灯效果
方法一:(只能实现单个TextView的跑马灯效果)在TextView添加以下控件 android:singleLine="true"只能单行,超出的文字显示为"...& ...
- TextView的跑马灯效果实现
TextView的跑马灯效果实现 问题描述 当文字内容过长,但是只允许显示一行时,可以将文字显示为跑马灯效果,即文字滚动显示. 代码实现 第一种方法实现 先查询TextView控件的属性,得到以下信息 ...
- Android使用TextView实现跑马灯效果(自定义控件)
对于一个长的TetxView 折行显示是一个很好的办法,另一种方法就是跑马灯显示(单行滚动) 1.折行显示的长TextView <LinearLayout xmlns:android=" ...
- JavaScript小实例-文字跑马灯效果
我们常常能看到显示屏上字体的滚动以及手机弹幕等,下面所示代码就是一个简易的文字跑马灯的效果: <!DOCTYPE html> <html> <head lang=&quo ...
随机推荐
- scrapy爬取西刺网站ip
# scrapy爬取西刺网站ip # -*- coding: utf-8 -*- import scrapy from xici.items import XiciItem class Xicispi ...
- transform做2d和3d变形(css动画一)
前言:这是笔者学习之后自己的理解与整理.如果有错误或者疑问的地方,请大家指正,我会持续更新! 有段时间我是没理清transform.translate.transition和animation之间的关 ...
- c++简单线程池实现
线程池,简单来说就是有一堆已经创建好的线程(最大数目一定),初始时他们都处于空闲状态,当有新的任务进来,从线程池中取出一个空闲的线程处理任务,然后当任务处理完成之后,该线程被重新放回到线程池中,供其他 ...
- C#之FTP上传下载(一)
搭建FTP服务器 最近要实现这样一个功能:FTP服务器的上传和下载,搜集了一些资料,在c播客上看到昵称为"傻丫头和科技"的作者写的一篇文章写得挺好,有的地方个人觉得不是很详细,自己 ...
- 对于手机APP偷窥个人隐私,你怎么看
经过进两周的持续发酵,Facebook5000万用户数据泄露事件,已让其处在舆论的风尖浪口.对于手机APP泄漏用户个人隐私问题,再次受到人们的关注.对于这个问题,你会怎么看? 隐私,即不愿公开的个人信 ...
- [LeetCode] Maximum Swap 最大置换
Given a non-negative integer, you could swap two digits at most once to get the maximum valued numbe ...
- 织云Lite发布:详解包管理核心能力
本文由 织云平台团队 发布于 腾讯云云+社区 织云Lite发布 腾讯织云自动化运维体系经过10年技术积淀,维护近万个业务模块,超过20万节点.鉴于业界朋友的呼声,我们将织云的核心功能独立抽象出来,凝结 ...
- 毕业回馈--89C51keil工程的创建
声明:毕业回馈类博客均为大学毕业前夕同同学共享内容.为了给大学做一个总结,报答母校的栽培,才发起这样一个活动. ******************************************** ...
- Centos常用命令之:ln
在linux中[ln]这个命令用来创建连接文件. 共有两种连接文件:一种是类似与Windows的快捷方式(软链接),另一种就是通过文件系统的inode来产生的新的文件名(硬链接). 这里解释下什么叫i ...
- [AHOI 2009]chess 中国象棋
Description 题库链接 给你一张 \(N\times M\) 的棋盘.要求每行每列最多放两个棋子,问总方案数. \(1\leq N,M\leq 100\) Solution 记 \(f_{i ...