在UIView中幻灯片放映

时间:2011-11-03 06:36:37

标签: iphone objective-c cocoa-touch

我需要使用UIImageView在UIView中实现幻灯片放映。是否有任何代码在运行时使用计时器加载图像视图?如果任何人可以请提供代码,这将是有帮助的。 在此先感谢.....

2 个答案:

答案 0 :(得分:1)

Use this one:

NSArray *imageArray = [NSArray arrayWithObjects: [UIImage imageNamed:@"nature1.png"], [UIImage imageNamed:@"nature2.png"], [UIImage imageNamed:@"nature3.png"], [UIImage imageNamed:@"nature4.png"],[UIImage imageNamed:@"nature5.png"],[UIImage imageNamed:@"nature6.png"] nil];
UIImageView *slidShowImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,320,480)];
slidShowImageView.animationImages = imageArray; 
slidShowImageView.animationDuration = 0.25; 
 slidShowImageView.animationRepeatCount = 0; 
[slidShowImageView startAnimating]; 
[self addSubview:slidShowImageView]; 
[slidShowImageView release]; 

答案 1 :(得分:0)

使用代码为视图设置动画...

UIImageView * campFireView = [[UIImageView alloc] initWithFrame:self.view.frame];

// load all the frames of our animation
campFireView.animationImages = [NSArray arrayWithObjects:    
                                [UIImage imageNamed:@"welcome-1.tiff"],
                                [UIImage imageNamed:@"welcome-2.tiff"],
                                [UIImage imageNamed:@"welcome-3.tiff"],
                                nil];

// all frames will execute in 1.75 seconds
campFireView.animationDuration = 1.00;
// repeat the annimation forever
campFireView.animationRepeatCount = 0;
// start animating
[campFireView startAnimating];
// add the animation view to the main window 
[self.view addSubview:campFireView];