I'm using the following code to move an UIImageView across screen. With this code it rockets across the screen but I want it to slowly move. What do I need to do?
[UIView beginAnimations:#"slide-up" context:NULL];
astroid_1.center = CGPointMake(astroidPosX,astroidPosY); // change this to somewhere else you want.
[UIView commitAnimations];
Thanks!
You need to set the duration of the animation:
[UIView setAnimationDuration:1.0];
Related
I am making a iPhone/iPad app with a cursor and music. I am running a timer every beat and moving it like so:
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:theLength];
[UIView setAnimationBeginsFromCurrentState:YES];
theCursor.frame = CGRectMake(theX, 0, 6, 320);
[UIView commitAnimations];
However, it seems to start off fast then slow down as it gets to the end. Is there any way to make the animation steady?
That's the animation curve. By default it is set to UIViewAnimationCurveEaseInOut. Use setAnimationCurve: to set it to UIViewAnimationCurveLinear.
You should also be aware that that way of animating is deprecated and Apple now recommend using the block-based animation style.
My code does an animation that flips from right to left. The problem is while its switching, only a .75 second animation, the user is still able to interact with the program. I dont want them to be able to, is there a way to stop all user interaction for a short time, or just a way to stop it completely, then i can just use a timer to put it back on. here is my code for the animation:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.75];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight
forView:[self view]
cache:YES];
[UIView commitAnimations];
Thanks, Jacob
Try:
[self.view setUserInteractionEnabled:NO];
I have a small UIView and want to let it move to center of screen first, and then, zoom to full screen.
But when I begin start an animation like
[UIView beginAnimations:#"animation1" context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(showDetailToFullscreen)];
self.currentDetailVC.frame = centerFrame;
[UIView commitAnimations];
And in the same controller, I have a method:showDetailToFullscreen
- (void)showDetailToFullscreen {
CGRect screenFrame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height);
[UIView beginAnimations:#"animation2" context:nil];
[UIView setAnimationDuration:0.5];
self.currentDetailVC.view.frame = screenFrame;
[UIView commitAnimations];
}
but when start, it still executed together.
I think the problem they are still in the same transaction. But how can I let these two animation executed one by one? Appreciate for any answer!
Try this instead of the setAnimationDidStopSelector:
[self performSelector:#selector(showDetailToFullscreen) withObject:nil afterDelay:0.5];
It's now considered much better to annimate views using the 'blocks' methods that can be found in the "Animating Views with Blocks" section in the UIView Class Reference.
In most of these methods you can specify a "completion" block of code that can be used to start off a second animation when the first animation completes. You could also call showDetailToFullscreen within this completion block.
I'd reccommend trying this method instead.
Are you targetting iOS 4 or later? If so, I recommend using the block-based animation methods instead. What you want to do is very easy:
Example from UIView docs:
[UIView animateWithDuration:0.2
animations:^{view.alpha = 0.0;}
completion:^(BOOL finished){ [view removeFromSuperview]; }];
I have an iPad 3.2 project where if you swipe left or right, it goes to a duplicate view with all the elements updated with the new data. However, in iOS 4.0 you can use transitionWithView:duration:options:animations:completion: on a single view to do the same thing.
So my question is, using Core Animation, can I do the same thing in iOS 3.2? I'm badly running out of RAM because having a duplicate view (a very complicated view) is using up a lot of memory and I'm running into memory warnings.
Thanks!
:-Joe
[self.view addSubview:myNewView];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:duration];
[UIView setAnimationTransition:transition forView:view cache:YES];
// do view modifications that you did in the animations block
CGRect frame = myOldView.frame;
myNewView.frame = frame;
frame.origin.x = 320;
[myOldView setFrame:frame];
[UIView commitAnimations];
Below is code that I'm using to swap views
MySecondViewController *tempVC = [[MySecondViewController alloc] initWithNibName:#"MySecondView"];
[self presentModalViewController:tempVC animated:YES];
[tempVC passDataWithString:#"a string" andColor:yellowcolor];
How can I get the cool page turning animation (as with iBook or ROAD RAGE SIGN)
I don't want the user to actually tap and drag his finger on the screen. I want him to push a button and the animation occurs by itself.
Have you looked at UIViewAnimationTransition values? Use them in a UIView animation block. eg:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationTransition: UIViewAnimationTransitionCurlUp
forView:self.view cache:YES];
[UIView commitAnimations];