iphone image change with motion - iphone

hi is there any way to set image [uiimage image named#"abc.png"] with the motion effect means the image should not be changed at once , it need to change with very slow motion effect so that user can see that image is now changing .
Thanks in advance

* Method one to perform the Animation *
Step 1 : Add following framework in your project and import it to your .m file
#import <QuartzCore/QuartzCore.h>
Step 2 : Write following code in your ImageChange method
imageView.image = [UIImage imageNamed:#"newImage.jpg"];
CATransition *transition = [CATransition animation];
transition.duration = 1.0f;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionFade;
[imageView.layer addAnimation:transition forKey:nil];
* Method Two to perform the Animation *
[UIView transitionWithView:YourImageView
duration:0.2f
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^{
YourImageView.image = newImage;
} completion:NULL];

Related

Slide Image 400px from Current Location with CATransition

I have a UIImageView that I have aligned right where I want it in my XIB file. When my viewController is called, I would like to have the image move to the right about 400px over the course of 3 seconds. Then I would like the image to fade-out.
I have been playing around with QuartzCore and CATransition and have been able to fade an image out over time with:
CATransition *animation = [CATransition animation];
animation.type = kCATransitionFade;
animation.duration = 0.4;
[coverImage.layer addAnimation:animation forKey:nil];
coverImage.hidden = true;
However, I would like the image to slide to the right. Anyone know how to do this? Thank you!
Using CATransition for moving images is quite overkill. I would recommend using UIView animations, then you would simply do
// UIImageView *coverImage = ...
// This will move the image to the right and then fade it out.
[UIView animateWithDuration:3 animations:^{
coverImage.center = CGPointMake(coverImage.center.x + 400, coverImage.center.y);
coverImage.alpha = 0.0f;
}];
UIImageView *coverImage=[[UIImageView alloc] initWithFrame:CGRectMake(0, 300, 200, 400)];
coverImage.backgroundColor = [UIColor blackColor];
[self.view addSubview:coverImage];
[UIView animateWithDuration:0.4 animations:^{
coverImage.frame = CGRectInset(coverImage.frame, -400, 0);
coverImage.alpha = 0.0f;
}];
//there is subtype property which provides transition from right or from left. You have to just set this property as given below
animation.subtype = kCATransitionFromRight;

Stopping CATransition animation

I'm using this code to make ripple animation for my view
transition = [CATransition animation];
transition.delegate = self;
transition.duration = 3;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
NSString *types[4] = {#"cube", #"rippleEffect", #"cube", #"alignedCube"};
NSString *subtypes[4] = {kCATransitionFromLeft, kCATransitionFromRight, kCATransitionFromTop, kCATransitionFromRight};
transition.type = types[1];
transition.subtype = subtypes[1];
Now I want to stop the animation by means of tap and after that I want to start from the view where I stopped....
I tried for
[view.layer removeAllAnimations];
But I found the following thing doesn't work ..Any Suggestions???
Set the speed of your animation to 0 to pause it and to 1 to resume it again.
Take a look at https://developer.apple.com/library/ios/#qa/qa2009/qa1673.html
You can fetch the current animation state from the CALayer.
#import <QuartzCore/QuartzCore.h>
myView.layer.modelLayer.frame = myView.layer.presentationLayer.frame;

iphone - UIImagePickerController... making it appear from the right

I have to present a UIImagePickerController but when I do so, it always come from the bottom up. Is there a way to make it appear from the right to left?
I have tried this without success:
CATransition* transition = [CATransition animation];
transition.duration = 0.35f;
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromLeft;
[self.navigationController.view.layer addAnimation:transition forKey:kCATransition];
[self.navigationController presentModalViewController:picker animated:YES];
thanks
I assume you are currently displaying the picker by calling presentModalViewController:animated: and passing YES as the animated option.
What you can do instead is present without animating, and instead cover the appearance using your own transition animation. The example below would present from the right:
CATransition *transition = [CATransition animation];
transition.duration = 0.5;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionMoveIn;
transition.subtype = kCATransitionFromRight;
[self.view.window.layer addAnimation:transition forKey:nil];
[self presentModalViewController:pickerController animated:NO];
To use this you'll need to #import <QuartzCore/QuartzCore.h> and add the QuartzCore framework to the project.

Animate the CHANGE of UIImageView only one image

I have a UIImageView that I would like to change its image with animation. I checked how to animate a UIImageView with an array but I don't wanna use many image.
I just wanna change the current image with a a new one using any kind of animation only once.
I think you can find your answer on this
The animationImages property works equally well with one image in it, or multiple.
Just put the below code:
#import <QuartzCore/QuartzCore.h>
...
imageView.image = [UIImage imageNamed:"The image name"];
CATransition *transition = [CATransition animation];
transition.duration = 1.0f;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionFade;
[imageView.layer addAnimation:transition forKey:nil];
I think you are searchig for this......

Swapping a UIImageView's image while rotating and moving leaves traces of original image

I am taking the "Flipped Text" imageView and rotating it while moving it downwards on the screen and adjusting the frame. I am also swapping out the image for a different, but similar image.
Everything works as indicated except for the image crossfade is still showing the original position for the fade-out instead of following the movement. This screenshot shows the original, transition and end states for the animation, and clearly shows the problem.
My code looks like this (logoImage is a UIImageView):
// Swap it
self.logoImage.image = [UIImage imageNamed:#"logo.png"];
CATransition *transition = [CATransition animation];
transition.duration = duration;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionFade;
[self.logoImage.layer addAnimation:transition forKey:nil];
// Spin it
CABasicAnimation* spinAnimation = [CABasicAnimation animationWithKeyPath:#"transform.rotation"];
spinAnimation.toValue = [NSNumber numberWithFloat:6*M_PI];
spinAnimation.duration = duration;
spinAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
spinAnimation.removedOnCompletion = YES;
spinAnimation.fillMode = kCAFillModeForwards;
[self.logoImage.layer addAnimation:spinAnimation forKey:#"spinAnimation"];
// Shrink it and Move it
CGRect newFrame = [self logoFrameForInterfaceOrientation:self.interfaceOrientation];
[UIView animateWithDuration:duration
delay:0.0
options:UIViewAnimationCurveEaseOut
animations:^{
self.logoImage.frame = newFrame;
}
completion:nil];
How can I make the crossfade of the image swap happen in place?
Try swapping the image in the completion block. (currently nil)
edit:
If they are substantially different, you can use a second UIImageView. Fade one out while you fade one in. You can either do this while they are translating, or wait for the "shrunken" original to arrive and fade it out while the "better" smaller version fades in.
Then remove the unneeded extra view in the completion block of that animation.