In iOS app, we may have a requirement like, when a user tap on a button , a UIView slide down with animation . To implement this we can create a button and UIView on the top of button and make it hidden . Then in action method of the button change the frame of the UIView with animation according to our requirement . To make it hide again with animation like slide top, reverse the operation .
Here is an example in which we will make a UIView slide down when a user tap on the button.
1) Create a UIButton
2) Then create a UIView on the top of UIButton and make it hidden . Lets say we named it myView
3) Then in action method of UIButton , check if button is hidden or not and act accordingly:
if([myView isHidden]){
First unhide the button
myView.hidden = NO;
Get the frame of the btn
CGRect frame = myView.frame
Now change the y origin of the frame
frame.origin.y += 30;
Now set animation to change the frame of the myView
[UIView animateWithDuration:0.7 delay:0.0
options:UIViewAnimationOptionCurveLinear animations:^{
myView.frame = frame
} completion:nil];
That's all . Now if we want to slide top the myView again ,when user tap on the button then change the frame of the myView to its original size .
No comments:
Post a Comment