How can I implement image flip animation towards right. the code given below. plz help .
imageview.animationImages=[NSArray arrayWithObjects:
[UIImage imageNamed:#"image1.png"],
[UIImage imageNamed:#"imag2.png"],
[UIImage imageNamed:#"imag3.png"],
[UIImage imageNamed:#"imag4.png"],
[UIImage imageNamed:#"imag5.png"],
[UIImage imageNamed:#"imag6.png"],
[UIImage imageNamed:#"imag7.png"], nil];
imageview.animationDuration=15.0;
imageview.animationRepeatCount=0;
[imageview startAnimating];
for vertical flip
[UIView animateWithDuration:1.0 animations:^{
yourView.layer.transform = CATransform3DMakeRotation(M_PI,1.0,0.0,0.0);
} completion:^(BOOL finished){
// code to be executed when flip is completed
}];
for horizontal flip
[UIView animateWithDuration:1.0 animations:^{
yourView.layer.transform = CATransform3DMakeRotation(M_PI,0.0,1.0,0.0);
} completion:^(BOOL finished){
// code to be executed when flip is completed
}];
and don't forget to add QuartzCore framework to the project and importing
#import <QuartzCore/QuartzCore.h>
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:imageview cache:NO];
[UIView commitAnimations];
I think This code may help you.
Related
The following method that i created for animation:
-(void)shakingAnimationForGate:(UIImageView *)image leftShaking:(CGAffineTransform)leftTransform rightShaking:(CGAffineTransform)rightTransform animationName:(NSString *)string{
[UIView animateWithDuration:5.0
delay:0.5
options: UIViewAnimationOptionCurveEaseOut
animations:^{
image.transform = leftTransform; // starting point
[UIView beginAnimations:string context:(__bridge void *)(image)];
[UIView setAnimationRepeatAutoreverses:YES]; // important
[UIView setAnimationRepeatCount:20];
[UIView setAnimationDelay:0.1];
[UIView setAnimationDuration:0.06];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(shakeEnded:finished:context:)];
image.transform = rightTransform; // end here & auto-reverse
[UIView commitAnimations];
}
completion:^(BOOL finished){
NSLog(#"end of shaking");
}];
}
which makes UIView do the "shaking".
Then i'm using this method:
CGAffineTransform leftShake = CGAffineTransformMakeTranslation(-2, 6);
CGAffineTransform rightShake = CGAffineTransformMakeTranslation(0, 3);
[self shakingAnimationForGate:imageLeft leftShaking:leftShake rightShaking:rightShake animationName:#"left view shake"];
where imageLeft is UIImageView.
So my problem is that this method don't do animation of shaking on iOS 6.1. It's working fine on iOS 7 though. Any ideas what's the problem?
When compiling, Xcode optimises your code a little. For example if you execute the following code, only the last line is executed:
[self.view setBackgroundColor:[UIColor greenColor]];
[self.view setBackgroundColor:[UIColor yellowColor]];
Most likely that's the case with the animation as well.
Move the revert part to the completion part.
I am trying to remove a subview form a view with animation like below. However, when I click a button to run the code, the view is removed immediately. Does anyone know what happen here.
Thanks,
CGRect rect=[self.view viewWithTag:10].frame;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationDidStopSelector:#selector(removeLayer)];
[[self.view viewWithTag:10] setFrame:CGRectMake(rect.origin.x, btn.frame.origin.y, rect.size.width, 0)];
[UIView animateWithDuration:1.0 animations:^{[[self.view viewWithTag:10] setFrame:CGRectMake(rect.origin.x, btn.frame.origin.y, rect.size.width, 0)];} completion:^(BOOL finished){[[self.view viewWithTag:10] removeFromSuperview];}];
[UIView commitAnimations];
-(void)removeLayer{
[[self.view viewWithTag:10] removeFromSuperview];
}
It looks like you are trying to use two different animation methods simultaneously. All you need is:
CGRect rect=[self.view viewWithTag:10].frame;
[UIView animateWithDuration:1.0 animations:^{[[self.view viewWithTag:10] setFrame:CGRectMake(rect.origin.x, btn.frame.origin.y, rect.size.width, 0)];} completion:^(BOOL finished){[[self.view viewWithTag:10] removeFromSuperview];}];
You are combining both types of animation API - I think the block-based one is returning immediately so your didStopSelector is being called straight away.
Try just using this part of it:
[UIView animateWithDuration:1.0 animations:^{[[self.view viewWithTag:10] setFrame:CGRectMake(rect.origin.x, btn.frame.origin.y, rect.size.width, 0)];} completion:^(BOOL finished){[[self.view viewWithTag:10] removeFromSuperview];}];
I think that you forgot to set animation delegate:
[UIView setAnimationDelegate:self];
In your code UIView doesn't know to which object it should send "removeLayer" selector
I'm trying a flip or curl between to views in a container which works pretty well using the following code:
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:.8];
[UIView setAnimationTransition:animationOption
forView:container cache:YES];
[container addSubview:nuView];
[oldView removeFromSuperview];
[UIView commitAnimations];
but does not with
[UIView transitionWithView:container
duration:.8
options:animationOption
animations:^
{
[container addSubview:nuView];
[oldView removeFromSuperview];
}
completion:^(BOOL finished)
{
}];
Any ideas?
What is animationOption? This code works perfectly well in one of my apps:
[UIView transitionWithView:currentContainerView
duration:0.75
options:UIViewAnimationOptionTransitionFlipFromLeft
animations:^{
[currentContainerView.frontView removeFromSuperview];
[currentContainerView addSubview:currentContainerView.flippedSideView];
}
completion:^(BOOL finished) {
// stuff
}];
Check if you are using UIViewAnimationOptionTransition or UIViewAnimationTransition !
I'm having difficulty moving an image to another location after the first animation is finished.
the image animates at a point that I've specified, then stops (that works fine). I would then like to move the image to another location and repeat.
here's my code:
-(void) loadTap {
NSArray *imageArray = [[NSArray alloc] initWithObjects:
[UIImage imageNamed:#"tap1.png"],
[UIImage imageNamed:#"tap2.png"],
[UIImage imageNamed:#"tap3.png"],
[UIImage imageNamed:#"tap4.png"],
nil];
tapImage.animationImages = imageArray;
tapImage.animationRepeatCount = 1;
[imageArray release];
tapImage.animationDuration = 1;
tapImage.animationRepeatCount = 20;
[tapImage startAnimating];
tapImage.center = CGPointMake(156, 110);
}
thanks for any help.
In order to move an image, you should enclose the code to move in an animation block:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
tapImage.center = CGPointMake(156, 110);
[UIView commitAnimations];
You can also give a method to execute upon completion of the animation with UIView setAnimationDidStopSelector: method.
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(animateImages)];
tapImage.center = CGPointMake(156, 110);
[UIView commitAnimations];
//other stuff
-(void)animateImages{
[tapImage startAnimating];
}
I have 2 layer is top and bottom on my program
how can i remove top layer with animation or bring top layer to back is it possible?
The easiest is playing with frame and alpha before removing it.
You can get some cool effects
-(void)removeWithEffect:(UIView *)myView
{
[UIView beginAnimations:#"removeWithEffect" context:nil];
[UIView setAnimationDuration:0.5f];
//Change frame parameters, you have to adjust
myView.frame = CGRectMake(0,0,320,480);
myView.alpha = 0.0f;
[UIView commitAnimations];
[myView performSelector:#selector(removeFromSuperview) withObject:nil afterDelay:0.5f];
}
iOS Update
You can now use blocks to perform your animation
[UIView animateWithDuration:0.5f
animations:^{view.alpha = 0.0;}
completion:^(BOOL finished){ [view removeFromSuperview]; }];
If you're targetting iOS 4.0 upwards you can use animation blocks:
[UIView animateWithDuration:0.2
animations:^{view.alpha = 0.0;}
completion:^(BOOL finished){ [view removeFromSuperview]; }];
(above code comes from Apple's UIView documentation)