UIImageView以及动画
2015-09-04 10:12
423 查看
{
CGSize size = [UIScreen
mainScreen].bounds.size;
//演示UIImageView的使用,
主要显示图像(png,jpeg)
//<1>UIImageView
基本使用
UIImageView *back = [[UIImageView
alloc] initWithFrame:self.view.bounds];
//注意细节:
//不能显示gif,
使用第三方库显示
//png可以省略后缀名, jpg一定需要加后缀名
back.image = [UIImage
imageNamed:@"back2.jpg"];
// imageNamed图片做缓存,
如果图片太大
//back.image = [UIImage alloc] initWithData:<#(NSData *)#>;
NSLog(@"w=%f h=%f",back.image.size.width,back.image.size.height);
[self.view
addSubview:back];
//<2>UIImageView
如何实现动画
_bird = [[UIImageView
alloc] initWithFrame:CGRectMake(100, 100, 120, 96)];
_bird.image = [UIImage
imageNamed:@"DOVE 1.png"];
[self.view
addSubview:_bird];
//设置动画
//bird.animationDuration
//bird.animationImages
//bird.animationRepeatCount
NSMutableArray *images = [[NSMutableArray
alloc] init];
for (int i=1; i<=18; i++) {
NSString *name = [NSString
stringWithFormat:@"DOVE %d.png",i];
UIImage *image = [UIImage
imageNamed:name];
[images addObject:image];
}
_bird.animationImages = images;
//控制动画速度
_bird.animationDuration = 18 * 1.0/30;
[_bird
startAnimating];
//定时器,
很多操作每隔一段时间执行
//参数1:
每次执行的间隔
//参数2和3:
指定一个每次执行方法
//参数4:
传入用户数据
//参数5:
是否重复
[NSTimer
scheduledTimerWithTimeInterval:0.1
target:self
selector:@selector(dealLoop:)
userInfo:nil
repeats:YES];
}
-(void)dealLoop:(NSTimer *)t
{
double xSpeed = 10;
CGPoint center =
_bird.center;
center.x += xSpeed;
if(center.x >
self.view.frame.size.width
+ _bird.frame.size.width/2)
{
center.x = -
_bird.frame.size.width / 2;
}
_bird.center = center;
//语法有问题;
//_bird.center.x += 10;
//让敌机再次出现
}
CGSize size = [UIScreen
mainScreen].bounds.size;
//演示UIImageView的使用,
主要显示图像(png,jpeg)
//<1>UIImageView
基本使用
UIImageView *back = [[UIImageView
alloc] initWithFrame:self.view.bounds];
//注意细节:
//不能显示gif,
使用第三方库显示
//png可以省略后缀名, jpg一定需要加后缀名
back.image = [UIImage
imageNamed:@"back2.jpg"];
// imageNamed图片做缓存,
如果图片太大
//back.image = [UIImage alloc] initWithData:<#(NSData *)#>;
NSLog(@"w=%f h=%f",back.image.size.width,back.image.size.height);
[self.view
addSubview:back];
//<2>UIImageView
如何实现动画
_bird = [[UIImageView
alloc] initWithFrame:CGRectMake(100, 100, 120, 96)];
_bird.image = [UIImage
imageNamed:@"DOVE 1.png"];
[self.view
addSubview:_bird];
//设置动画
//bird.animationDuration
//bird.animationImages
//bird.animationRepeatCount
NSMutableArray *images = [[NSMutableArray
alloc] init];
for (int i=1; i<=18; i++) {
NSString *name = [NSString
stringWithFormat:@"DOVE %d.png",i];
UIImage *image = [UIImage
imageNamed:name];
[images addObject:image];
}
_bird.animationImages = images;
//控制动画速度
_bird.animationDuration = 18 * 1.0/30;
[_bird
startAnimating];
//定时器,
很多操作每隔一段时间执行
//参数1:
每次执行的间隔
//参数2和3:
指定一个每次执行方法
//参数4:
传入用户数据
//参数5:
是否重复
[NSTimer
scheduledTimerWithTimeInterval:0.1
target:self
selector:@selector(dealLoop:)
userInfo:nil
repeats:YES];
}
-(void)dealLoop:(NSTimer *)t
{
double xSpeed = 10;
CGPoint center =
_bird.center;
center.x += xSpeed;
if(center.x >
self.view.frame.size.width
+ _bird.frame.size.width/2)
{
center.x = -
_bird.frame.size.width / 2;
}
_bird.center = center;
//语法有问题;
//_bird.center.x += 10;
//让敌机再次出现
}
相关文章推荐
- Android Studio创建module缺少build文件夹
- String,StringBuffer与StringBuilder的区别??
- 原来UIWindow可以自定义frame
- sort与priority_queue的比较标准差异
- UILabel的文字与 label 的中间线对齐方式
- UILabel.text截取方式
- HDU 1005 Number Sequence(数论)
- POJ 2034 Anti-prime Sequences(数论+dfs)
- POJ 2478 Farey Sequence(欧拉函数)
- PHP基础----PHP常用功能----09include 与 require
- UI控件-----UIScrollView
- Leetcode Unique Binary Search Trees II
- Android酷炫的UI开源框架(转)
- hdu 4915 Parenthese sequence(贪心,模拟)
- IOS开发UI—Button基础
- UITextField相关使用方法
- SPOJ 375 Query on a tree(树链剖分)
- Meteor:应用UI状态
- [leetcode-115]Distinct Subsequences(java)
- easyUI 笔记