Image with animation in iphone - iphone

I want to use the image in view which will move like marquee as in HTML,from one end to another end of view.
Could anyone provide me with that code how to do that.
Thanks in advance n please help me out with this.

It was the new Blocks API which introduced in iOs 4.0
Use this if you are not yet in 4.0
CABasicAnimation *theAnimation;
theAnimation=[CABasicAnimation animationWithKeyPath:#"transform.translation.x"];
theAnimation.duration=1;
theAnimation.repeatCount=2;
theAnimation.autoreverses=YES;
theAnimation.fromValue=[NSNumber numberWithFloat:0];
theAnimation.toValue=[NSNumber numberWithFloat:-60];
[view.layer addAnimation:theAnimation forKey:#"animateLayer"];
This bit of code moves the view 60 pixels to the left then back to its original position
[please dont forget to vote if you find this answer useful :-) ]

Use uiview's transition effects..
[UIView AnimateWithDuration: delay: options: animations: completion: ];
methode.
repeat transition with some nice effects.

Related

Problems with UIView animation

I am performing animation on my view. But I am facing few problems with that. I have to button's startAnimation and Stop Animation. For performing animation on my imageview I am using following code in startAnimation button's action:
UIViewAnimationOptions option = UIViewAnimationOptionRepeat + UIViewAnimationOptionAutoreverse;
[UIView animateWithDuration:2.5 delay:0.0 options:option
animations:^{
CGAffineTransform scale = CGAffineTransformMakeScale(2.0, 2.0);
CGAffineTransform translate = CGAffineTransformMakeTranslation(-50.0, -100.0);
CGAffineTransform mix = CGAffineTransformConcat(scale, translate);
imv.transform = mix;
}
completion:^(BOOL finished) {
}
];
This is working.
Now the problems I am facing are:
How to stop this animation on my stopAnimation button's action?
If ImageView is animation and I enter in background after that I again come in foreground ImageView sticks there and do not animates.
How to solve these issues?
On your stopAnimation button you would need to remove animations from the UIView's layer. First you must import Quartzcore.framework.
#import <QuartzCore/QuartzCore.h>
[yourView.layer removeAllAnimations];
As for your other issue of pausing your animation while going into the background and coming back to foreground, theres no way to 'pause' an animation. Your best bet would be to manually handle that situation by restarting your animation.
To stop the animation you can use
#import <QuartzCore/QuartzCore.h>
...
[imv.layer removeAllAnimations];
As for making an animation restart it is a complex problem and the answer depends on what you want the application to do when it restores. One possible answer would be to keep track of where you are animating the ImageView to and then in ApplicationDidEnterBackground you could cancel all the animations and simply move it there. Then when you restored it would be in the correct location.
If you actually want to continue the animations I would have a read of some other Stack Overflow answers and see if that helps.
Restoring animation where it left off when app resumes from background
iOS, Restarting animation when coming out of the background
For further reference, for the second part of your response you have to restore the matrix to the identity before doing anything:
imv.transform = CGAffineTransformIdentity;

iOS Core Animation Police Light Flashing Light Effect

EDIT: Per the provided comments, I have specified my question to a more direct implementation and desired solution.
Hello there,
I want a blue light, a red light, and potentially a neutral colored light, all appearing to be spinning in circles (similar to if a police car was nearby, you would see the lights flashing/rotating colors).
Here's a screenshot of the red and blue image views that I'm currently using to try to make the effect.
The following code currently varies each view layer's opacity:
[UIView animateWithDuration:4.5
delay: 1.0
options: UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionCurveLinear
animations:^{
[self startRedAnimation];
[self startBlueAnimation];
}
completion:^(BOOL finished){}];
My animation method looks like the following:
- (void)startRedAnimation
{
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:#"opacity"];
[animation setFromValue:[NSNumber numberWithFloat:0.75]];
[animation setToValue:[NSNumber numberWithFloat:0.1]];
[animation setDuration:0.5f];
[animation setTimingFunction:[CAMediaTimingFunction
functionWithName:kCAMediaTimingFunctionLinear]];
[animation setAutoreverses:YES];
[animation setRepeatCount:16];
[[_redLightView layer] addAnimation:animation forKey:#"opacity"];
}
You can imagine that the blueLightView animation method looks similar.
What I'm looking for is to have the views appear to rotate, IE they are not just flashing their opacity from 0 to 1, but rather altering color and/or rotating around in a circle on the view.
I'd like to use QuartzCore and CoreAnimation frameworks to make this happen, instead of just UIView animations over an array of images.
I'm relatively new to CoreAnimation and have performed similar effects like rotating/pulsing view layers, but I'm just not certain what I could use from the framework that would give me the effect I'm looking for.
Any insight would be greatly appreciated! Thanks Stack Overflow peers!
Try to move the images instead of changing the colors. I could imagine that you could achieve the desired effect by rotating the images around the bottom of the screen back and forth.

How to animate bars of barchart-coreplot

I am new to iphone development and coreplot.
I want to draw a barchart according to some data, that i have done.
now i want to give some animations to the bars of plot. That means bars in the graph should lengten or shorten in a growing or shrinking efect.
Can anybody help me?
Thanks in advance.
Kindly refer the following post:
How to access CALayer of individual bar in core-plot?
It talks about precisely the same thing you are trying to do.
I dont know what class you might be using, but most probably it is a subclass of CA Layer.
Check this code out:
CABasicAnimation *rotation = [CABasicAnimation animationWithKeyPath:#"transform"];
CATransform3D transform = CATransform3DMakeRotation(DegreesToRadians(360), 0, 0, 1);
rotation.toValue = [NSValue valueWithCATransform3D:transform];
rotation.duration = 10.0f;
[pieChart addAnimation:rotation forKey:#"rotation"];
How to animate the pie charts developed using core-plot library?

Core-Plot iPhone Animation Examples

I've been looking into core-plot for the iPhone and I'm having trouble finding any examples of animation actually being used.
What I need to see is an example of how to use core-plots animation to add an extra plot to a graph when someone clicks a button.
If anyone can produce and example, or show me a link to one, that would be great.
Regards,
Craig
The official CPAnimation classes within Core Plot are just stubs right now. At some point, we'll enable the full functionality of those.
In the meantime, every visible element in Core Plot is a Core Animation CALayer, so you can animate these using existing Core Animation methods. For example, if you have a plot called dataSourceLinePlot (like in the test Core Plot iPhone application), you could start the plot off with an opacity of 0.0:
dataSourceLinePlot.opacity = 0.0f;
[graph addPlot:dataSourceLinePlot];
and then animate its opacity to fade it in:
CABasicAnimation *fadeInAnimation = [CABasicAnimation animationWithKeyPath:#"opacity"];
fadeInAnimation.duration = 1.0f;
fadeInAnimation.removedOnCompletion = NO;
fadeInAnimation.fillMode = kCAFillModeForwards;
fadeInAnimation.toValue = [NSNumber numberWithFloat:1.0];
[dataSourceLinePlot addAnimation:fadeInAnimation forKey:#"animateOpacity"];
This will fade in a new plot on an existing graph over a one second interval. You could also do something similar to animate it in from a side or use a transform to scale it up into position. CATransitions could also be used to achieve these kind of effects.
EDIT (1/17/2010): The Core Plot iPhone test application now contains an example of the fade-in animation described above.

How can I replicate the trashing animation of Mail.app

In my iPhone app, I have put a UIBarBUtton of type UIBarButtonSystemItemTrash in my UIToolBar. When pressed, I'd like to replicate the animation of Mail.app: the bin opens, the UIView folds and flies into it.
Is there a way to access this animation ithrough the iPhone SDK?
Presently I am using a custom made animation, but there are some limits; for example, I cannot animate the bin itself.
Do you have any suggestion? Code samples?
Cheers,
Davide
Use the suckEffect type on an animation. Also: spewEffect, genieEffect, unGenieEffect, twist, tubey, swirl, cameraIris, cameraIrisHollowClose, cameraIrisHollowOpen, rippleEffect, charminUltra, zoomyIn, and zoomyOut. Doesn't work in the simulator.
CATransition *animation = [CATransition animation];
animation.type = #"suckEffect";
animation.duration = 2.0f;
animation.timingFunction = UIViewAnimationCurveEaseInOut;
view.opacity = 1.0f;
[view.layer addAnimation:animation forKey:#"transitionViewAnimation"];
Note: Code snippet was pulled from a larger codebase. I hope it works :)
Just to add some info:
You can use "suckEffect" with the standard +[UIView setAnimationTransition:forView:cache:]. Just pass the number 103 to the animationTransition variable. This won't avoid your app being rejected by Apple though :p
"spewEffect", "genieEffect", "unGenieEffect", etc. no longer exist on iPhoneOS 3.x. The only undocumented transition left are "cube" (--), "rippleEffect" (110), the three "cameraIris" effects (105,106,107) and "suckEffect" (103).
See http://www.iphonedevwiki.net/index.php?title=UIViewAnimationState for detail.
Also, to animate the bin (with private API): http://www.iphonedevwiki.net/index.php?title=UIToolbar#Animating_the_trash_can_icon.
Unfortunately, I think this is going to need to be an entirely custom animation. The UIView folding can be approximated using Core Animation, perhaps by adding perspective to the CATransform3D of the UIView's underlying layer to distort the UIView into a trapezoid which gets sucked into the trash can.
As far as the trash can, you can create a UIBarButtonItem using initWithCustomView:, which might let you insert a custom UIView that has an animatable trashcan. It looks like the trash can has two elements, the can base and the lid, which are rotated independently to open and close the can. Draw PNGs for both, make UIImageViews for them, and make them subviews of the UIBarButtonItem custom view. For opening and closing, apply rotational transforms to them to animate the subviews.
I'm not sure if this is an answer but here is lib that do "genie effect" so it's quite similar to what you want achieve.
CGRect endRect = CGRectMake(30, 40, 50, 60);
[view genieInTransitionWithDuration:0.7
destinationRect:endRect
destinationEdge:BCRectEdgeTop
completion:^{
NSLog(#"I'm done!");
}];