iphone练习之实现图片切换(用代码实现)
3秒切换到:
新建一个基于视图的项目,命名为Animation2,往项目中放入几个图片!!
直接在Animation2ViewController.m中实现代码:
- (void)viewDidLoad
{
//定义数组,存放所有图片对象
NSArray *images=[NSArray arrayWithObjects:[UIImage imageNamed:@"xuanyi.jpg"],[UIImage imageNamed:@"xigua.jpg"],[UIImage imageNamed:@"juhua.jpg"],[UIImage imageNamed:@"heihua.jpg"],[UIImage imageNamed:@"cell.jpg"], nil];
//定义结构体,方块大小
CGRect frame=CGRectMake(0, 0, 320, 460);
//初始化图像视图对象,大小是frame
UIImageView *imageView = [[UIImageView alloc] initWithFrame:frame];
//imageView的动画图片是数组images
imageView.animationImages = images;
//按照原始比例缩放图片,保持纵横比
imageView.contentMode = UIViewContentModeScaleAspectFit;
//切换动作的时间3秒,来控制图像显示的速度有多快,
imageView.animationDuration = 3;
//动画的重复次数,想让它无限循环就赋成0
imageView.animationRepeatCount = 0;
//开始动画 www.2cto.com
[imageView startAnimating];
//添加控件
[self.view addSubview:imageView];
//释放内存
[imageView release];
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)viewDidLoad
{
//定义数组,存放所有图片对象
NSArray *images=[NSArray arrayWithObjects:[UIImage imageNamed:@"xuanyi.jpg"],[UIImage imageNamed:@"xigua.jpg"],[UIImage imageNamed:@"juhua.jpg"],[UIImage imageNamed:@"heihua.jpg"],[UIImage imageNamed:@"cell.jpg"], nil];
//定义结构体,方块大小
CGRect frame=CGRectMake(0, 0, 320, 460);
//初始化图像视图对象,大小是frame
UIImageView *imageView = [[UIImageView alloc] initWithFrame:frame];
//imageView的动画图片是数组images
imageView.animationImages = images;
//按照原始比例缩放图片,保持纵横比
imageView.contentMode = UIViewContentModeScaleAspectFit;
//切换动作的时间3秒,来控制图像显示的速度有多快,
imageView.animationDuration = 3;
//动画的重复次数,想让它无限循环就赋成0
imageView.animationRepeatCount = 0;
//开始动画
[imageView startAnimating];
//添加控件
[self.view addSubview:imageView];
//释放内存
[imageView release];
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
ok,实现图片切换!!
ok!实现!本博客是我自己的练习,有好多地方没有讲太清楚,还请谅解!
相关新闻>>
- 发表评论
-
- 最新评论 更多>>