How do I animate the movement of a view in iOS? How do I animate the movement of a view in iOS? objective-c objective-c

How do I animate the movement of a view in iOS?


For most animations, you can simply change the properties of the view inside a UIView animation block. The UIView class documentation lists which properties are animatable.

[UIView animateWithDuration:0.5f animations:^{    aView.frame = CGRectOffset(aView.frame, 0, 250); }];

Here is a sample project demonstrating how you would trigger an animation when a button is pressed. You could put this animation code many other places, so there isn't a good answer to your question about where to put the code unless you give more details about what you want.

https://github.com/MaxGabriel/AnimationDemonstration

The approach you were taking was animating a UIImageView. I've never done this, but my understanding is that's like making an animated GIF. For things like moving views or fading them out, you'll want to use the animation block method shown above.


It is simple to do animation in iOS.

CGRect basketTopFrame = self.upperview.frame;basketTopFrame.origin.y = -basketTopFrame.size.height;CGRect basketBottomFrame = self.lowerview.frame;basketBottomFrame.origin.y = self.view.bounds.size.height;[UIView beginAnimations:nil context:nil];[UIView setAnimationDuration:1.0];[UIView setAnimationDelay:1.0];[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];self.upperview.frame = basketTopFrame;self.lowerview.frame = basketBottomFrame;[UIView commitAnimations];


The following code work for me, to move a view when open a keyboard or other things.

[UIView animateWithDuration:(timeYouWantAnimate - 0.3f) animations:^{ [nameOfView setFrame:CGRectMake(0,spaceYouWantMove like -100, self.view.with, self.view.height)];}

Hope can help you too :D