2015-12-23 32 views
0

我有一个UIView在X = 0和Y = 0位置的高度为110和UIButton在屏幕的底部与50的高度,我想同时显示动画,但UIView必须动画从顶部到其高度和UIButton从底部到它的高度,我是这个全新的请帮助我如何做到这一点。从上到下动画UIview从上到下,反之亦然

回答

1

可满足您的要求基本的动画

[UIView transitionWithView:view 
        duration:0.5 
        options:UIViewAnimationOptionTransitionNone 
       animations:^{ 
        //update your frame here; 
       } 
       completion:nil]; 

请到通Apple Documentationstack overflow

0

下面的代码为我工作,以显示在顶部的搜索视图。

if (!isSearchActive) { 
    [UIView animateWithDuration:0.4 
          delay:0.1 
         options: UIViewAnimationOptionCurveEaseIn 
        animations:^{ 
         searchView.frame = CGRectMake(0, 56, mainWidth, 50); 
        } 
        completion:^(BOOL finished){ 
        }]; 
    isSearchActive=YES; 
} 
else{ 
    [UIView animateWithDuration:0.3 
          delay:0.1 
         options: UIViewAnimationOptionCurveEaseIn 
        animations:^{ 
         searchView.frame = CGRectMake(0, 56, mainWidth, 0); 
        } 
        completion:^(BOOL finished){ 
        }]; 
    isSearchActive=NO; 
} 

调用此代码可以单击任意按钮来显示和隐藏视图。

0

尝试此从上到下动画:

- (CAAnimation*)movedown; 
{ 
    CABasicAnimation *animation = [CABasicAnimation animation]; 
    animation.keyPath = @"position.y"; 
    animation.fromValue = @600; 
    animation.toValue = @50; 
    animation.duration = 0.25; 

    animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]; 


    [trashView.layer addAnimation:animation forKey:@"basic"]; 
    trashView.layer.position =CGPointMake(0,-20); 
    return animation; 
} 

和规范自下而上 -

- (CAAnimation*)moveup; 
{ 
    CABasicAnimation *animation = [CABasicAnimation animation]; 
    animation.keyPath = @"position.y"; 
    animation.fromValue = @-500; 
    animation.toValue = @10; 
    animation.duration = 0.25; 

    animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]; 


    [trashView.layer addAnimation:animation forKey:@"basic"]; 
    trashView.layer.position =CGPointMake(0,20); 
    return animation; 

} 

为的代码,你可以用它来制作动画视图第一个块,但你必须更换viewcontrollertrashview代码。

和第二块用于按钮,但你必须更换你的按钮在trashview

但您可以根据需要设置动画的值。

+0

我已经试过这个,它运作良好。只是你必须改变价值和设置动画。 –