iphone 利用UIImageView来制作幻灯片
在 iPhone 应用里加入全屏动画可以让应用更具趣味性,以下这段代码可以实现这一功能
AnimationDemoViewController.m
- (void)viewDidLoad {
[super viewDidLoad];
//指定ImageView的展示区域
UIImageView *fishAni=[UIImageView alloc] initWithFrame:[UIScreen mainScreen] bounds];
//将指定的图片载入至 animationImages
可以利用NSFileManage从文件夹中读取图片,并显示。。
fishAni.animationImages=[NSArray arrayWithObjects:
[UIImage imageNamed:@"1.jpg"],
[UIImage imageNamed:@"2.jpg"],
[UIImage imageNamed:@"3.jpg"],
[UIImage imageNamed:@"4.jpg"],
[UIImage imageNamed:@"5.jpg"],nil ];
//设定动画播放时间
fishAni.animationDuration=1.0;
//设定重复播放次数,0 为不断重复
fishAni.animationRepeatCount=0;
//开始播放动画
[fishAni startAnimating];
//将ImageView 增加到 self.view 的 subview
[self.view addSubview:fishAni];
}
思路:可添加两种按钮,一个是暂停动画按钮,一个是开始动画按钮。
代码如下:
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
{
UIImageView *fishAni;
UIButton *startAnimationBtn;
UIButton *endAnimationBtn;
}
-(void) startAnimationBtnClick:(id)sender;
-(void) endAnimationBtnClick:(id)sender;
@end
实现文件:
#import "ViewController.h"
@implementation ViewController
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
//创建一个按钮
startAnimationBtn= [UIButton buttonWithType:UIButtonTypeRoundedRect ];
startAnimationBtn.frame = CGRectMake(20,400, 40, 30);
//startAnimationBtn = [[UIButton alloc] initWithFrame:CGRectMake(20, 280, 40, 30)];
[startAnimationBtn setTitle:@"Start" forState:UIControlStateNormal];
[startAnimationBtn setTitleColor:[UIColor redColor] forState:UIControlStateSelected];
[startAnimationBtn setTitleShadowColor:[UIColor greenColor] forState:UIControlStateNormal];
[startAnimationBtn addTarget:self action:@selector(startAnimationBtnClick:) forControlEvents:UIControlEventTouchUpInside];
//停止动画
endAnimationBtn = [UIButton buttonWithType:UIButtonTypeInfoLight];
endAnimationBtn.frame = CGRectMake(120, 280, 40, 30);
// endAnimationBtn = [[UIButton alloc] initWithFrame:CGRectMake(120, 280, 40, 30)];
[endAnimationBtn setTitle:@"End" forState:UIControlStateNormal];
[endAnimationBtn setTitleColor:[UIColor redColor] forState:UIControlStateSelected];
[endAnimationBtn setTitleShadowColor:[UIColor greenColor] forState:UIControlStateNormal];
[endAnimationBtn addTarget:self action:@selector(endAnimationBtnClick:) forControlEvents:UIControlEventTouchUpInside];
//制定ImageView的展示区域
fishAni = [[UIImageView alloc] initWithFrame:[UIScreen mainScreen].bounds];
//将制定的图片载入至 animationImages
fishAni.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"xiaomao1.jpg"],
[UIImage imageNamed:@"xiaomao2.jpg"],
[UIImage imageNamed:@"xiaomao3.jpg"],
[UIImage imageNamed:@"xiaomao4.jpg"],nil];
//设定动画播放时间
fishAni.animationDuration = 3.0;
fishAni.animationRepeatCount = 0;
fishAni.highlighted = YES;
[fishAni startAnimating];
[self.view addSubview:fishAni];
[self.view addSubview:startAnimationBtn];
[self.view addSubview:endAnimationBtn];
}
-(void) startAnimationBtnClick:(id)sender
{
[fishAni startAnimating];
}
-(void) endAnimationBtnClick:(id)sender
{
[fishAni stopAnimating];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
}
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
@end
转载于:https://www.cnblogs.com/angelfeather/articles/5946570.html
iphone 利用UIImageView来制作幻灯片相关推荐
- 用Beamer制作幻灯片(卷三 动画篇)
在前面的两个章节中主要讲解的是怎么制作幻灯片的大体框架,要使得幻灯片更吸引眼球我们就还需要为其添加一些动画. 1.覆盖 覆盖是最为基本的一种幻灯片效果.严格地说,它甚至不是"动态" ...
- 如何用计算机完成一片文稿制作,怎样在家用电脑上制作幻灯片?
利用PowerPoint 2000轻松制作课件 多媒体课件已经越来越广泛地应用在现代化教育中,许多教师可能觉得课件制作的难度比较高.其实PowerPoint 2000是一个很方便的课件制作软件,方便大 ...
- Pandoc中使用Reveal-js制作幻灯片
工具:Typora (markdown编辑器) + Pandoc + reveal.js 如果需要使用 pandoc 命令,则需将 pandoc 添加到 path 环境变量中 Pandoc pando ...
- 怎样用计算机做ppt,怎样在家用电脑上制作幻灯片?
利用PowerPoint 2000轻松制作课件 多媒体课件已经越来越广泛地应用在现代化教育中,许多教师可能觉得课件制作的难度比较高.其实PowerPoint 2000是一个很方便的课件制作软件,方便大 ...
- 用计算机制作演示文稿教案博客,《轻松制作幻灯片》教案
<轻松制作幻灯片>教案 教学目标: 知识与技能: 1.学会选择ppt板式,会在ppt中插入图片.文本框.艺术字等基本方法. 2.会保存ppt文件. 过程与方法: 1.使学生能主动参与学习活 ...
- 用计算机制作演示文稿教案博客,《制作幻灯片》教学设计
<制作幻灯片>教学设计 ------插入图片与文本框 教学目标: 知识与能力目标: 学会在PowerPoint中插入图片.文本框. 过程与方法目标: 1.使学生能主动参与学习活动,善于与人 ...
- 用Beamer制作幻灯片(卷一 基本架构篇)
首先,如果你是安装CTex的话,建议您先备份你的path路径.以免以后比较麻烦,以后安装之后会修改path路径,我说的是在Windows系统下. Latex是很好的排版工具,我们使用Latex中的Be ...
- reveal.js + markdown 制作幻灯片
reveal.js + markdown 制作幻灯片--0 reveal.js是一款通过利用HTML快速创建演示文稿,并且具有很多功能:垂直,水平幻灯片:支持Markdown,LaTex:演讲者注释: ...
- reveal.js + markdown 制作幻灯片——配置选项,幻灯片背景,尺寸,插入媒体,链接
reveal.js + markdown 制作幻灯片--配置选项,幻灯片背景,尺寸,插入媒体,链接 配置选项 配置选项在index.html文件的<body>中,通过Reveal.init ...
- 用Beamer制作幻灯片(卷二 色彩篇)
在用Beamer类制作幻灯片卷一里讲解了怎么使用Latex的简单的类来制作幻灯片,只是给了基本的怎么制作幻灯片的一个大体框架.但是一个很好的幻灯片远远不止这些功能. beamer的功能还有很多.今天要 ...
最新文章
- java 工厂模式的写法_Java23种设计模式之抽象工厂模式
- [IOI2014]Wall
- MySQL查询的进阶操作--分页查询
- sortable vue 排序_VUE +element el-table运用sortable 拖拽table排序,实现行排序,列排序...
- 【ORACLE 高可用】作业 :配置ORACLE GoldenGate 2
- .NET CORE(C#) WPF 抽屉式菜单
- [JS]关于表单的自动运算(已解决)
- 苹果邮箱 android设置字体,苹果6邮件怎么设置qq邮箱怎么设置几号字体
- 如何利用shell查看Ubuntu系统版本号和电脑类型
- a:link,a:visited,a:hover,a:active
- 打印一只Nyan Cat(彩虹猫)(C++)
- Android 7.1开机之后APN的加载及拨号上网流程分析
- ”VT-x is not available (VERR_VMX_NO_VMX)“ 和 “VBoxManage: error: Details: code NS_ERROR_FAILURE”问题
- 计算机科学导论-绪论
- [Arcpy] 0 Arcpy初识 | Arcpy开发思路
- 快速将PDF图片转成PPT
- SysDVR Switch 串流到笔记本
- postgreSQL查询 获取行号 rownum,解决方案
- python实例手册
- Several approaches to non-archimedean geometry
热门文章
- Website English Comments
- 同一个页面Button OnClientClick事件 和服务器验证控件提交问题
- SQL Server 2008 Mirror
- 如何解决MFC读取文件在EditControl中显示是乱码的问题
- matlab矩阵的表示和简单操作
- Sauceware Audio Scorch for Mac - 嘻哈说唱音频乐器
- Toontrack EZbass for mac - 虚拟低音音频插件
- EasyRecovery解救打工人的崩溃
- Cannot change version of project facet Dynamic Web Module to 2.5解决方案
- px2rem 第三方库实践