Reputation:
I have a set of images which i want to display as a slideshow.Is there any transition effects i can apply on UIImageView
.
[imgView setImage:[UIImage imageNamed: @"images.jpeg"]];
Upvotes: 1
Views: 812
Reputation: 3928
Try with below code:
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];
Upvotes: 0
Reputation:
Here is a sample code of how to create a slide show. Make sure you import some images unto your project and in the case method change the wall images to the name of your images.
- (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;
}
Upvotes: 1
Reputation: 6445
Yes you can apply transition effects on UIImageView.
First you need to import QuartzCore framework.
#import <QuartzCore/QuartzCore.h>
Then you can use the CoreAnimation as below:
[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];
Or you can simply animate a group of images in UIImageView as
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];
Upvotes: 3