1

我作为初学者正在学习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];
4

2 回答 2

1

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

设置框架所做的只是设置视图的框架。

于 2013-07-01T06:56:00.493 回答
1

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

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

于 2013-07-01T06:56:16.900 回答