hello i have this simple animation here that slides photos automatically.i just want to add extra effects on the slides thing like flipping or fading.please help me
- (void)viewDidLoad
{
[super viewDidLoad];
imageView.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:#"6.png"],
[UIImage imageNamed:#"2.png"],
[UIImage imageNamed:#"3.png"], nil];
imageView.animationDuration = 15.00; //5 seconds each
imageView.animationRepeatCount = 0; //infinite
[imageView startAnimating]; //start the animation
}
To do that, you're going to need to go past UIImageView's animationImages property and manage the animations yourself using UIView transitionWithView and nest such. Like so.
[UIView transitionWithView:imageView duration:5 options:UIViewAnimationOptionTransitionFlipFromBottom animations:^{
imageView.image = [UIImage imageNamed:#"6.png"];
} completion:^(BOOL done){
[UIView transitionWithView:imageView duration:5 options:UIViewAnimationOptionTransitionFlipFromBottom animations:^{
imageView.image = [UIImage imageNamed:#"2.png"];
} completion:^(BOOL done){
[UIView transitionWithView:imageView duration:5 options:UIViewAnimationOptionTransitionFlipFromBottom animations:^{
imageView.image = [UIImage imageNamed:#"3.png"];
} completion:^(BOOL done){
}];
}];
}];
Related
In my app, I need to set up an animation that will run on repeat until I perform an action on it. I want both an image to change, and text change along with it. I am trying now the suggested key frame animations, but it is only showing the last change and no repeats. I have done some searches and looking at the documentation, but I'm definitely still missing something.
It was my understanding that the animateKeyframesWithDuration is measured in seconds, while relative start and relative duration are 0 - 1 in value, so I set each to be 0.2, as there are 5, and 0.2 is exactly a fifth. What am I doing wrong? All of the NSLogs fire, but none of the events actually change, other than the final one.
[UIView animateKeyframesWithDuration:70 delay:0 options:UIViewKeyframeAnimationOptionRepeat animations:^{
[UIView addKeyframeWithRelativeStartTime:0 relativeDuration:0.2 animations:^{
NSLog(#"a1");
self.eventsText.text = nil;
theImageView.image = [UIImage imageNamed:#"welcome.png"];
}];
[UIView addKeyframeWithRelativeStartTime:0.2 relativeDuration:0.2 animations:^{
NSLog(#"a12");
theImageView.image = [UIImage imageNamed:#"pleasepray.png"];
self.eventsText.text = #"Test2";
}];
[UIView addKeyframeWithRelativeStartTime:0.4 relativeDuration:0.2 animations:^{
NSLog(#"a13");
theImageView.image = [UIImage imageNamed:#"comingevents.png"];
self.eventsText.text = #"Test3";
}];
[UIView addKeyframeWithRelativeStartTime:0.6 relativeDuration:0.2 animations:^{
NSLog(#"a14");
theImageView.image = [UIImage imageNamed:#"birthdays.png"];
self.eventsText.text = nil;
}];
[UIView addKeyframeWithRelativeStartTime:0.8 relativeDuration:0.2 animations:^{
NSLog(#"a14");
theImageView.image = [UIImage imageNamed:#"ournumbers.png"];
self.eventsText.text = #"Test4";
}];
} completion:nil];
Ok, so here's what I ended up doing. I only have 5 different "slides" that I need to rotate through, and some of them without text. For now, I put text into an Array to simulate what I need. In the future, this will be dynamic, pulled from a server. I then set up an NSInteger property to link everything together, and pull from this array to go along with how long each animation of the images takes.
-(void)announcementsTime {
[self rotatewarmup];
_timer = [NSTimer scheduledTimerWithTimeInterval:14.0 target:self selector:#selector(rotatewarmup )userInfo:nil repeats:YES];
[[NSRunLoop currentRunLoop] addTimer: _timer forMode: NSDefaultRunLoopMode];
}
-(void)rotatewarmup
{
theImageView.hidden = NO;
NSArray *imagesArray = [NSArray arrayWithObjects:
[UIImage imageNamed:#"welcome.png"],
[UIImage imageNamed:#"pleasepray.png"],
[UIImage imageNamed:#"comingevents.png"],
[UIImage imageNamed:#"birthdays.png"],
[UIImage imageNamed:#"contribution2.png"],
nil];
if (self.songNumber == 0) {
if (_firingTime == 4) {
self.eventsText.text = self.allInfo[_firingTime];
theImageView.image = imagesArray[_firingTime];
_firingTime = 0;
}
else {
self.eventsText.text = self.allInfo[_firingTime];
theImageView.image = imagesArray[_firingTime];
NSInteger newFiring = _firingTime + 1;
_firingTime = newFiring;
}
}
else {
self.eventsText.text = #"";
}
}
I am making an image editor application.
I am able to change the UIImage of a UIImageView but I want it to be more efficient and beautiful.
Currently I am changing UIImage as
if(image)
{
userImageView.image = image;
}
It directly changes the UIImage. How can I make a fadeIn-fadeOut effect?
UIImage *image = [UIImage imageWithData:imageData];
[UIView transitionWithView:YourUIImageView
duration:2.0f
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^{
YourUIImageView.image = image;
} completion:nil];
And Do some googling before asking this question already has and answer.
Check THIs
try this...
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.fadeDuration=1;
}
return self;
}
-(void)setImage:(UIImage *)newImage{
if(!self.image||self.fadeDuration<=0){
super.image=newImage;
} else {
UIImageView *iv=[[UIImageView alloc] initWithFrame:self.bounds];
iv.contentMode=self.contentMode;
iv.image=super.image;
iv.alpha=1;
[self addSubview:iv];
super.image=newImage;
[UIView animateWithDuration:self.fadeDuration delay:0 options:UIViewAnimationCurveEaseInOut animations:^{
iv.alpha=0;
} completion:^(BOOL finished) {
[iv removeFromSuperview];
}];
}
}
Try something like this:
-(void)fade{
//fade out
[UIView animateWithDuration:1.0f animations:^{
[userImageView setAlpha:0.0f];
} completion:^(BOOL finished) {
//fade in
[UIView animateWithDuration:1.0f animations:^{
userImageView.image = image;
[userImageView setAlpha:1.0f];
} completion:nil];
}];
}
i got a button to show an image in the UIImageView. what i need to do is to get this image to fade out by itself in 2 seconds, is it possible to do so?
here is my code on the button:
- (IBAction)A {
UIImage *Img = [UIImage imageNamed:#"AString.png"];
[ImageView setImage:Img];
}
thank you in advance...
Try this:
- (IBAction)A
{
UIImage *Img = [UIImage imageNamed:#"AString.png"];
[ImageView setImage:Img];
Img.hidden = NO;
Img.alpha = 1.0f;
[UIView animateWithDuration:2 delay:0 options:0 animations:^{
Img.alpha = 0.0f;
} completion:^(BOOL finished) {
Img.hidden = YES;
}];
}
Try this code :
yourImageView.hidden = YES;
[UIView transitionWithView:yourImageView
duration:2
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^{
[self.view layoutIfNeeded]; // Called on parent view
}
completion:NULL];
I'm making a very simple game. I have a UIButton and an UIImageView. What I'm trying to do is that when the user presses the button, it will change the image to another image and then back to the original image, to simulate an animation (Character moving)
I have this code:
file.m
{
IBOutlet UIImageView *image1;
IBOutlet UIButton *button;
}
-(IBAction)button:(id)sender;
file.h
-(IBAction)button:(id)sender{
[UIView animateWithDuration:1.0f
animations:^{
image1.alpha = 0.1f;
} completion:^(BOOL finished) {
image1.image = [UIImage imageNamed:#"image2.png"];
[UIView animateWithDuration:0.2f
animations:^{
image1.alpha = 1.0f;
} completion:^ (BOOL finished) {
image1.image = [UIImage imageNamed:#"image1.png"];
}];
}];
}
When I open the iOS simulator and press the button, the image dissolves, then reappears and then does the animation. The problem is that I don't want it to dissolve, I just want to show the animation. How do I prevent this from happening? Is it because I'm using alpha properties?
Thank you!
I used the following code to do what I think is what you need (shown here: https://www.dropbox.com/s/vtcyw0n257tgihx/fade.mov?dl=0):
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:#selector(test)];
iv = [[UIImageView alloc] initWithFrame:CGRectMake(100, 100, 150, 150)];
iv.image = [UIImage imageNamed:#"red"];
[self.view addSubview:iv];
}
- (void)test {
[UIView animateWithDuration:1.0f animations:^{
iv.alpha = 0.0f;
} completion:^(BOOL finished) {
iv.image = [UIImage imageNamed:#"blue"];
[UIView animateWithDuration:1.0f animations:^{
iv.alpha = 1.0f;
} completion:^ (BOOL finished) {
[UIView animateWithDuration:1.0f animations:^{
iv.alpha = 0.0f;
} completion:^ (BOOL finished) {
iv.image = [UIImage imageNamed:#"red"];
[UIView animateWithDuration:1.0f animations:^{
iv.alpha = 1.0f;
} completion:nil];
}];
}];
}];
}
You need to break it down into four parts. First you need to fade the original image out, change it to the second image, fade the second image in, fade the second image out, change back to the original image, then fade it back in.
i tried to make this slideshow repeat for infinity and didn't work.please help me
-(void)viewDidLoad
{
[super viewDidLoad];
[NSTimer scheduledTimerWithTimeInterval:15 target:self selector:#selector(changeImage) userInfo:nil repeats:YES];
}
-(void)changeImage
{
[UIView transitionWithView:imageView duration:5 options:UIViewAnimationOptionTransitionFlipFromBottom animations:^{
imageView.image = [UIImage imageNamed:#"6.png"];
} completion:^(BOOL done){
[UIView transitionWithView:imageView duration:5 options:UIViewAnimationOptionTransitionFlipFromBottom animations:^{
imageView.image = [UIImage imageNamed:#"2.png"];
} completion:^(BOOL done){
[UIView transitionWithView:imageView duration:5 options:UIViewAnimationOptionTransitionFlipFromBottom animations:^{
imageView.image = [UIImage imageNamed:#"3.png"];
} completion:^(BOOL done){
}];
}];
}];
}
Rather than Doing this You can use inbuilt property of UIImageview for animation images.
You can try Something Like,
NSArray *images = [NSArray arrayWithObjects:
[UIImage imageNamed:#"6.png"],
[UIImage imageNamed:#"2.png"],
[UIImage imageNamed:#"3.png"],
nil];
imageView.animationImages = images;
imageView.animationDuration = 1;
imageView.animationRepeatCount = 0; // 0 = nonStop repeat
[imageView startAnimating];
You can get this from example : http://goo.gl/8Gj6m0