Reputation: 19238
I am learning objective-c as a beginner and i am a bit lost over the setFrame, why animation required to have a setFrame, what does it really do in here? Could someone please explain? Thanks for any suggestions.
Thanks
-(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];
Upvotes: 1
Views: 733
Reputation: 124997
why animation required to have a setFrame, what does it really do in here?
You certainly don't need an animation to set the frame of a view, but setting the frame inside an animation will cause the change to be animated. That is, instead of moving _viewAccordionMenu
to its new position immediately, setting the frame in an animation will cause the view to move over ANIMATION_DURATION
seconds. This often looks nicer than having a view jump from one place to another.
Upvotes: 1
Reputation: 56625
The animation is "required" to have an animated change. setFrame
will work just fine without it but will jump to the new value without an animation.
All that set frame does is to set the frame of the view.
Upvotes: 1