Reputation: 13
I have UIScrollView where placed elements(elements placed from the top to down), how can I remove one row and smoothly move items up, without redrawing?
Upvotes: 1
Views: 732
Reputation: 3592
Well, an easy way to move UIViews (and subclasses) is using Core Animation.
An example, let's assume you want to move an UIImageView
10 pixels up, this is how I would do that:
[UIView beginAnimations:@"animation" context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
[UIView setAnimationDuration:1.0]; //In seconds
int newPosY = myImage.frame.origin.y - 10;
[myImage setFrame:CGRectMake(self.frame.origin.x, newPosY, myImage.frame.size.width, myImage.frame.size.height)];
[UIView commitAnimations];
EDIT: (Thanks to LucasTizma) Since Apple doesn't recommend this method you'd better use animateWithDuration:animations:
or any of it's variants. Check this
Upvotes: 0
Reputation: 8667
As for the removal of views, you need to use CATransition
. UIView
animations will not work when you remove, as this concept isn't animatable in the context of an animation. However, there the concept of a transition makes sense:
CATransition *transition = [CATransition animation];
transition.duration = 0.4;
[someView.layer addAnimation:transition forKey:kCATransition];
[someView removeFromSuperview];
Note that the order in which you make a change to a layer and when you add the animation to the layer doesn't matter, as long as it occurs within the same stack frame (i.e., as long as it happens before the next main run loop cycle).
As for shifting things around, use UIView
animation methods:
[UIView animateWithDuration:0.4 animations:
^{
// Change the frames, bounds, etc. of any number of views here
}];
Upvotes: 1