开发者

Smoothly move elements on UIScrollView

开发者_如何学JAVAI 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?


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
}];


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜