我有一组想要以幻灯片形式显示的图像。我可以在UIImageView
上应用任何过渡效果。
[imgView setImage:[UIImage imageNamed: @"images.jpeg"]];
答案 0 :(得分:3)
是的,您可以在 UIImageView 上应用过渡效果。
首先,您需要导入 QuartzCore 框架。
#import <QuartzCore/QuartzCore.h>
然后您可以使用 CoreAnimation ,如下所示:
[imgView setImage:[UIImage imageNamed: @"images.jpeg"]];
CATransition *transition = [CATransition animation];
transition.duration = 1.0f;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionFade;
[imgView.layer addAnimation:transition forKey:nil];
或者您可以简单地为 UIImageView 中的一组图像设置动画
imgView.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"image1.jpeg"],
[UIImage imageNamed:@"image2.jpeg"],
[UIImage imageNamed:@"image3.jpeg"],
[UIImage imageNamed:@"image4.jpeg"], nil];
imgView.animationDuration = 1.0f;
imgView.animationRepeatCount = 0;
[imgView startAnimating];
答案 1 :(得分:1)
以下是如何创建幻灯片的示例代码。确保将一些图像导入到项目中,并在案例方法中将墙图像更改为图像名称。
- (IBAction)start:(id)sender {
_button.hidden = YES;
[NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(photoCounter) userInfo:nil repeats:YES];
}
- (void)photoCounter {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.90];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:NO];
[self updatePhoto];
[UIView commitAnimations];
}
- (void)updatePhoto
{
switch (imageCount)
{
case 0:
_images.image = [UIImage imageNamed:@"wall1.jpg"];
break;
case 1:
_images.image = [UIImage imageNamed:@"wall2.jpg"];
break;
case 2:
_images.image = [UIImage imageNamed:@"wall3.jpg"];
break;
case 3:
_images.image = [UIImage imageNamed:@"wall4.jpg"];
break;
case 4:
_images.image = [UIImage imageNamed:@"wall5.jpg"];
break;
default:
break;
}
imageCount ++;
if (imageCount > 4)
imageCount = 0;
}
答案 2 :(得分:0)
尝试使用以下代码:
NSArray *imageNames = @[@"2_1014.png", @"2_1015.png", @"2_1016.png", @"2_1017.png",@"2_1018.png", @"2_1019.png", @"2_1020.png", @"2_1021.png",@"2_1022.png", @"2_1023.png", @"2_1024.png", @"2_1025.png",@"2_1026.png", @"2_1027.png", @"2_1028.png",
@"2_1029.png",@"2_1030.png",@"2_1030.png",@"2_1029.png",
@"2_1028.png",@"2_1027.png",@"2_1026.png",@"2_1025.png",
@"2_1024.png",@"2_1023.png",@"2_1022.png",@"2_1021.png",
@"2_1020.png",@"2_1019.png",@"2_1018.png",@"2_1017.png",
@"2_1016.png",@"2_1015.png",@"2_1014.png"];
NSMutableArray *images = [[NSMutableArray alloc] init];
for (int i = 0; i < imageNames.count; i++) {
[images addObject:[UIImage imageNamed:[imageNames objectAtIndex:i]]];
}
// Normal Animation
animationImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, [UIScreen mainScreen].bounds.size.height)];
animationImageView.animationImages = images;
animationImageView.animationRepeatCount=0;
animationImageView.animationDuration = 1;
[self.view addSubview:animationImageView];
[animationImageView startAnimating];