Objective C动画setFrame

时间:2013-07-01 06:51:35

标签: objective-c

我正在学习Objective-c作为初学者而且我对 setFrame 有点迷失,为什么动画需要有一个setFrame,它在这里真正做了什么?有人可以解释一下吗?谢谢你的任何建议。

由于

-(void)showAccordionMenuInView:(UIView *)targetView{
    ...
    // STEP 5: ANIMATE
    [UIView beginAnimations:@"" context:nil];
    [UIView setAnimationDuration:ANIMATION_DURATION];
    [UIView setAnimationCurve:UIViewAnimationCurveLinear];
    [self.view setAlpha:0.5];
    // Set the yPoint value as the y origin point of the menu view
    // and the tempMenuHeight value as its height.
    **[_viewAccordionMenu setFrame:CGRectMake(_viewAccordionMenu.frame.origin.x,
                                            yPoint,
                                            _viewAccordionMenu.frame.size.width,
                                            tempMenuHeight)];**
    [UIView commitAnimations];

2 个答案:

答案 0 :(得分:1)

动画是“必需的”以进行动画更改。如果没有它,setFrame会正常工作,但会在没有动画的情况下跳转到新值。

所有设置框架都是设置视图的框架。

答案 1 :(得分:1)

  

为什么动画需要有一个setFrame,它在这里真正做了什么?

您当然不需要动画来设置视图的帧,但在动画内设置帧将导致更改动画。也就是说,不是立即将_viewAccordionMenu移动到新位置,而是在动画中设置帧将使视图移动ANIMATION_DURATION秒。这通常看起来比从一个地方跳到另一个地方更好。