It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I want to animate a image up and down smoothly. Any one has idea how to do it..
take a look at a easy UIView (UIImageView) animation tutorial
One of the coolest things about iPhone apps is how animated many of them are. You can have views fly across the screen, fade in or fade, out, rotate around, and much more!
Not only does this look cool, but animations are good indicators that something is going on that a user should pay attention to, such as more info becoming available.
Make sure you import following frameworks:
#import <QuartzCore/QuartzCore.h>
#import <CoreGraphics/CoreGraphics.h>
UIImageView *someImage = .....
CALayer *b = someImage.layer;
// Create a keyframe animation to follow a path to the projected point
CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:#"scale"];
animation.removedOnCompletion = NO;
// Create the path for the bounces
CGMutablePathRef thePath = CGPathCreateMutable();
// Start the path at my current location
CGPathMoveToPoint(thePath, NULL, someImage.center.x, someImage.center.y);
CGPathAddLineToPoint(thePath, NULL,20, 500.0);
animation.path = thePath;
animation.speed = 0.011;
animation.repeatCount = 1000000;
// Add the animation to the layer
[someImage addAnimation:animation forKey:#"move"];
You can play around with the values until you get your desired results. Accept this as the answer, if it's your solution.
- (void) showProgressView
{
if (progressViewBack.frame.origin.y == 460.0)
{
[self.view bringSubviewToFront:progressViewBack];
[progressViewBack setFrame:CGRectMake(6.0, 460, 308.0, 126.0)];
[progressViewBack setBounds:CGRectMake(0, 0, 308, 126.0)];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[UIView setAnimationDelegate:self];
[progressViewBack setFrame:CGRectMake(6.0, 334.0, 308.0, 126.0)];
[UIView commitAnimations];
}
else if (progressViewBack.frame.origin.y == 334.0)
{
[progressViewBack setFrame:CGRectMake(6.0, 334.0, 308.0, 126.0)];
[progressViewBack setBounds:CGRectMake(0, 0, 308.0, 126.0)];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[UIView setAnimationDelegate:self];
[progressViewBack setFrame:CGRectMake(6.0, 460.0, 308.0, 126.0)];
[UIView commitAnimations];
}
}
Related
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
How can I set animations in app delegate class?
Yes, you can show an animation just after your application loaded.
If you want to animate your "Default.png" to fade out for example when your application loaded, try this :
In AppNameAppDelegate.h :
#import UIKit/UIKit.h
#interface AppNameAppDelegate : NSObject {
UIImageView *splashView;
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
- (void)startupAnimationDone:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context;
#end
In AppNameAppDelegate.m :
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
[self.window makeKeyAndVisible];
splashView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0, 320, 480)];
splashView.image = [UIImage imageNamed:#"Default.png"];
[_window addSubview:splashView];
[_window bringSubviewToFront:splashView];
//Set your animation below
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationTransition:UIViewAnimationTransitionNone forView:_window cache:YES];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector (startupAnimationDone:finished:context:)];
splashView.frame = CGRectMake(-60, -60, 440, 600);
splashView.alpha = 0.0;
[UIView commitAnimations];
return YES;
}
- (void)startupAnimationDone:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
[splashView removeFromSuperview];
[splashView release];
}
I'm not sure if it's what are you looking for but maybe...
Hmm...
I think you will have to be a bit clearer.
You are not able to set an animation as the absolute first point of you application.
You can add an image named "Default.png" that will be shown when you application is loading.
There should be no major problems with showing an animation in you AppDelegate, but it will only sho AFTER your application is loaded.
I'm writing a card game and need a animation to flip them over from one side to the other along the y axses. What would be the easiest way to do this? Is there any good tutors?
This is what I did:
Found some sample code for using UITransitionView. But it comes up as undeclared on my sdk, and I found out this was undocumented.
Looked into OpenGL, seems to complicated.
Any help would be GREAT!
Ted
Here is some code that I used in a blackjack app tutorial I went through:
-(void) flipCard {
[UIView beginAnimations:#"Flip Top Card" context:nil];
[UIView setAnimationDidStopSelector:#selector(flipCardDone)];
[UIView setAnimationDuration:1];
[UIView setAnimationDelegate:self];
[UIView setAnimationRepeatCount:0];
[UIView setAnimationRepeatAutoreverses:NO];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut ];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:topCard cache:YES];
topCard.image = [UIImage imageNamed:#"back.png"]; //begin
topCard.image = [UIImage imageNamed:currentName]; //end
[UIView commitAnimations];
}
-(void) flipCardDone {
topCard.hidden = YES;
nextCardToFlip.hidden = NO; // bad var name, nextCardToFlip ONLY appears to flip.
}
I hope it helps you :)
The simplest way to do this would be to use UIView transitions, or CATransitions depending on what exactly you're trying to accomplish.
Documentation for the UIView animation can be found here.
This is an absolute beginner's question (sorry), but I was wondering how to commit one animations and once it has ended to start another one. Imagine having an image moved from x=0 to x=300. Then you want to do animate the same image again, but this time from x=300 to x=330 so that it disappears from the screen.
The following code will only do the animation from x=300 to x=330 and will not commit the animation x=0 to x=300. I'm sure I don't get the concept of commitAnnimation and that this is obvious, but how would I do two animations after one another?
I know I could move the image straightaway to 330, but I don't want this as I need the first animation (x 0 - 300) to be in sync with another animation.
Here is my (wrong) code:
[UIView beginAnimations:#"shadowMove" context:nil]; // Begin animation
[UIView setAnimationDuration:0.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[imageView setFrame:CGRectOffset([imageView frame], 300, 0)];
[UIView commitAnimations]; // End animations
// Second Animation
[UIView beginAnimations:#"shadowMoveRestAway" context:nil]; // Begin animation
[UIView setAnimationDuration:0.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[imageView setFrame:CGRectOffset([imageView frame], 330, 0)]; // Move imageView off screen
[UIView commitAnimations]; // End animations
Use the delegate method
[UIView setAnimationDidStopSelector:#selector(animationDidStop:finished:context:)];
to start something else when the first animation has finished. So put what you want to do next inside the animationDidStop:finished:context method, remember that the iphone is an event driven environment so linear code like you have above will simply kick off each animation at almost the same time.
EDIT:
I forgot to add that you need to set the animation delegate as well otherwise you won't get the event when the first one stops - see below;
Here's a full version of your code with the change - I'm using the abbreviated animationDidStop delegate as that's easier to understand and fine for this example.
[UIView beginAnimations:#"shadowMove" context:nil]; // Begin animation
[UIView setAnimationDuration:0.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(myFirstAnimationDidStop)];
[imageView setFrame:CGRectOffset([imageView frame], 300, 0)];
[UIView commitAnimations]; // End animations
Then you just need a new method like this;
-(void) myFirstAnimationDidStop {
// Second Animation
[UIView beginAnimations:#"shadowMoveRestAway" context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[imageView setFrame:CGRectOffset([imageView frame], 330, 0)];
[UIView commitAnimations];
}
And for completeness, in your interface (.h) file you should add;
-(void) myFirstAnimationDidStop;
#selector is easy, it's just a way of pointing to another method - hopefully this example clarifies that.
I have a client who recently requested this:
My thoughts were that the text could be better displayed on the back of a flipover view and that it looks like it could be an issue in the approval process. Is There any way to even do this, do I even want to try? Are there resources you can share?
Thanks in advance.
EDIT: I should clarify that the NavigationBar and the Table would slide over when taping the picture behind. One tap would make it show and the other tap would make the bar and the table hide.
This is actually pretty good. It's often hard to get clients to give you requirements, and this at least shows you what they're trying to achieve. I'd spend some time reworking the UI so that it will be acceptable in the app store (assuming you're going to publish there) and perhaps more in keeping with the normal use of iOS UI elements. Prepare to give your client a bit of an explanation about why this particular design leaves something to be desired, but try to come up with a design that they'll agree is obviously better. (There's plenty of room for improvement here, so it shouldn't be too hard.)
If your client is absolutely wedded to this exact UI, it might be time to find a new client. But if they're reasonable, thoughtful, and a little bit flexible, this might be the beginning of a nice app.
You can do this. Put the picture (UIImageView) inside a wrapper UIView. Put the text in a UITextView also in the wrapper UIView. Then animate a flip transition between them that brings whichever one you want to the bottom of the subview stack.
You can check for potential UI violations in Apple's HIG: http://developer.apple.com/library/ios/#documentation/UserExperience/Conceptual/MobileHIG/Introduction/Introduction.html
+(id)showAlert{
UIViewController *controller = [[UIViewController alloc] initWithNibName:#"Overlay" bundle:nil];
Overlay *alert = (Overlay*)controller.view;
//alert.iTag = iiTag;
alert.tag = iiTag;
return alert;
}
-(void)addAnimation{
self.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.001, 0.001);
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.3/1.5];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(bounce1AnimationStopped)];
self.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.1, 1.1);
[UIView commitAnimations];
}
- (void)bounce1AnimationStopped {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.3/2];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(bounce2AnimationStopped)];
self.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.9,0.9);
[UIView commitAnimations];
}
- (void)bounce2AnimationStopped {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.3/2];
self.transform = CGAffineTransformIdentity;
[UIView commitAnimations];
}
- (CGAffineTransform)transformForOrientation {
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
if (orientation == UIInterfaceOrientationLandscapeLeft) {
return CGAffineTransformMakeRotation(M_PI*1.5);
} else if (orientation == UIInterfaceOrientationLandscapeRight) {
return CGAffineTransformMakeRotation(M_PI/2);
} else if (orientation == UIInterfaceOrientationPortraitUpsideDown) {
return CGAffineTransformMakeRotation(-M_PI);
} else {
return CGAffineTransformIdentity;
}
}
-(void)stopAnimatton{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationDelay:2.0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDelegate:self];
self.transform = CGAffineTransformMake(00.1, 00.1,0.001, 0.001, 0.001, 0.001);
[UIView commitAnimations];
}
Is there any way to specify a duration for the animation of [UIScrollView zoomToRect:zoomRect animated:YES]?
At the moment it's either fast animated:YES or instant animated:NO.
I'd like to specify a duration, eg [UIScrollView setAnimationDuration:2]; or something similar.
Thanks in advance!
Use the UIView's animations.
It's a bit long to explain, so I hope this little example will clear things up a bit.
Look at the documantation for further instructions
[UIView beginAnimations: nil context: NULL];
[UIView setAnimationDuration: 2];
[UIView setAnimationDelegate: self];
[UIView setAnimationDidStopSelector: #selector(revertToOriginalDidStop:finished:context:)];
expandedView.frame = prevFrame;
[UIView commitAnimations];
It's from a project I'm currently working on so it's a bit specific, but I hope you can see the basics.
I've had luck with this method in a UIScrollView subclass:
- (void)zoomToRect:(CGRect)rect duration:(NSTimeInterval)duration
{
[self setZoomLimitsForSize:rect.size];
if (duration > 0.0f) {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:duration];
}
[self zoomToRect:rect animated:NO];
if (duration > 0.0f)
[UIView commitAnimations];
[self zoomToRect:rect animated:(duration > 0.0f)];
}
It's kinda cheating, but it seems to mostly work. Occasionally it does fail, but I don't know why. In this case it just reverts to the default animation speed.
Actually these answers are really close to what I ended up using but I'll post mine separately since it is different. Basically the zoomToRect does not work correctly if the destination zoomScale is the same as the current one.
You could try to scrollToRect but I did not have any luck with that.
Instead just use the contentOffset and set it to the zoomRect.origin and nest that in the animation block.
[UIView animateWithDuration:duration
delay:0.f
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
if (sameZoomScale) {
CGFloat offsetX = zoomRect.origin.x * fitScale;
CGFloat offsetY = zoomRect.origin.y * fitScale;
[self.imageScrollView setContentOffset:CGPointMake(offsetX, offsetY)];
}
else {
[self.imageScrollView zoomToRect:zoomRect
animated:NO];
}
}
completion:nil];