When UIView height set zero, view's child control not hide - ios

I want drawer animation. So I take 1 UIView and add 4 control inside UIView.
Now when I click on drawer button, set view height zero when drawer is close and set view height 200 when drawer is open.
But when I set zero height, button is not hide . All buttons are visible.
Auto layout is not in my project.
How to solved this problem.?
-(IBAction)Onclick_drawer:(id)sender
{
if(is_open)
{
is_open=false;
[UIView animateWithDuration:0.3
delay:0.0
usingSpringWithDamping:1.0
initialSpringVelocity:4.0
options: UIViewAnimationOptionCurveEaseInOut
animations:^{
self.drawer_view.frame=CGRectMake(0, 64, 320,200);
}
completion:^(BOOL finished){
}];
[UIView commitAnimations];
}
else
{
is_open=true;
[UIView animateWithDuration:0.3
delay:0.0
usingSpringWithDamping:1.0
initialSpringVelocity:4.0
options: UIViewAnimationOptionCurveEaseInOut
animations:^{
self.drawer_view.frame=CGRectMake(0, 64, 320, 0);
}
completion:^(BOOL finished){
}];
[UIView commitAnimations];
}
}

check in xib ... select view -> attribute inspector -> check clip Subviews like below image
or programatically use
self.yourview.clipsToBounds = YES;

Just select the view and go to right side of screen into attribute inspector
Check the check box for Clip Subviews

-(IBAction)Onclick_drawer:(id)sender
{
if(is_open)
{
is_open=false;
[UIView animateWithDuration:0.3
delay:0.0
usingSpringWithDamping:1.0
initialSpringVelocity:4.0
options: UIViewAnimationOptionCurveEaseInOut
animations:^{
self.drawer_view.frame=CGRectMake(0, 64, 320,200);
}
completion:^(BOOL finished){
}];
[UIView commitAnimations];
}
else
{
is_open=true;
[UIView animateWithDuration:0.3
delay:0.0
usingSpringWithDamping:1.0
initialSpringVelocity:4.0
options: UIViewAnimationOptionCurveEaseInOut
animations:^{
self.drawer_view.frame=CGRectMake(0, 64, 320, 0);
self.drawer_view.clipsToBounds = YES; // Need to add this line. This will clip all sub views into parent view
}
completion:^(BOOL finished){
}];
[UIView commitAnimations];
}
}

Related

Animation is happening in reverse

I'm making a simple animation where when a button is tapped it will change from current position to a certain point. But what's happening is the opposite: it goes from the destination point to the original position. Here's my code:
[UIView animateWithDuration:1.0
delay:0.0
usingSpringWithDamping:0.2
initialSpringVelocity:0.0
options:UIViewAnimationOptionBeginFromCurrentState
animations:^{
[self.view layoutIfNeeded];
CGFloat amount = 100;
self.checkButton.frame = CGRectOffset(self.checkButton.frame, amount, 0);
} completion:^(BOOL finished) {
}];
Make an outlet to the constraint that determine the horizontal position of the checkButton. e.g."hPos".
- (IBAction)tapHandler:(id)sender {
self.hPos.constant = self.hPos.constant + 100;
[UIView animateWithDuration:1.0
delay:0.0
usingSpringWithDamping:0.2
initialSpringVelocity:0.0
options:UIViewAnimationOptionBeginFromCurrentState
animations:^{ [self.view layoutIfNeeded]; }
completion:nil];
}

ios show Button with animation show one by one here i add link

I have six button on view with two pair of two grid.The problem is how to show button with animation, here I attach example url how to create this type of animation.
In this example when you click on menu button then show button in side menu view with animation
https://github.com/djardon/SideMenuFrostedAnimated
I tried this but I can't get any success.
I have two button one is btnHome and second is btnAbout:
-(void)animationStart
{
[btnHome setAlpha:0.f];
[UIView animateWithDuration:1.f delay:0.f options:UIViewAnimationOptionCurveEaseIn animations:^{
[btnHome setAlpha:0.f];
} completion:^(BOOL finished) {
[UIView animateWithDuration:2.f delay:0.f options:UIViewAnimationOptionCurveEaseInOut animations:^{
[btnHome setAlpha:1.f];
[self animationStart2];
} completion:nil];
}];
}
-(void)animationStart2
{
[btnAbout setAlpha:0.0f];
//fade in
[UIView animateWithDuration:2.0f animations:^{
[btnAbout setAlpha:1.0f];
} completion:^(BOOL finished) {
//fade out
[UIView animateWithDuration:2.0f animations:^{
[btnAbout setAlpha:0.0f];
} completion:nil];
}];
}
Try this.
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
btnHome.alpha=0.0;
btnAbout.alpha=0.0;
}
-(void)animationStart
{
[UIView animateWithDuration:0.4f delay:0.0f options: UIViewAnimationOptionCurveEaseInOut animations:^{
btnHome.alpha=1.0;
} completion:^(BOOL finished) {
[self animationStart2];
}];
}
-(void)animationStart2
{
[UIView animateWithDuration:0.4f delay:0.0f options: UIViewAnimationOptionCurveEaseInOut animations:^{
btnAbout.alpha=1.0;
} completion:^(BOOL finished) {
}];
}
- (IBAction)btnClick:(id)sender
{
[self animationStart];
}
Here initially i am setting the buttons alpha value to 0.0f. On click of third button i am showing these two buttons.

Show and hide UITableView with animation

I'm trying to show and hide a tableView with an animation "transition from left to right & right to left"
This what i already tired it worked but after using a random values in the CGRectMake,
Do anyone can help me to fix it please
-(void)Display:(UITableView *)tableView :(UIView *)view{
tableView.alpha=1;
[UIView animateWithDuration:0.35
animations:^{
tableView.frame = CGRectMake(-209, 440, 180, 209);
}
completion:^(BOOL finished){
[tableView setHidden:YES];
}
];
}
-(void)Hide:(UITableView *)tableView :(UIView *)view :(int )tb{
tableView.alpha=1;
[tableView setHidden:NO];
[UIView animateWithDuration:.45
animations:^{
tableView.frame = CGRectMake(3, 442, 180, 209);
}
];
}
You can use this code:
[UIView transitionFromView:firstView
toView:secondView//table view
duration:0.5
options:UIViewAnimationOptionTransitionFlipFromLeft
completion:^(BOOL finished) {
[firstView.superView addSubview:secondView];
[firstView.superView sendSubviewToBack:firstView];
}];
It's hard to tell from your question but by "transition from left to right & right to left"
do you want something like this...?
For animating out left
[UIView animateWithDuration:1.0f
delay:0.0f
options:UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionCurveEaseInOut
animations:^{
self.tableView.frame = CGRectMake(0.0f, -self.tableView.frame.size.width, self.tableView.frame.size.width, self.tableView.frame.size.height);
}
completion:NULL];
For animating out right
[UIView animateWithDuration:1.0f
delay:0.0f
options:UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionCurveEaseInOut
animations:^{
self.tableView.frame = CGRectMake(0.0f, self.view.bounds.size.width, self.tableView.frame.size.width, self.tableView.frame.size.height);
}
completion:NULL];
For animating in
[UIView animateWithDuration:1.0f
delay:0.0f
options:UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionCurveEaseInOut
animations:^{
self.tableView.frame = CGRectMake(0.0f, 0.0f, self.tableView.frame.size.width, self.tableView.frame.size.height);
}
completion:NULL];
You can put table reloads etc. in your completion blocks? and then animate the tableView back in?
If you want animation like Facebook then use :- ECSlidingViewController
http://kingscocoa.com/tutorials/slide-out-navigation/
Or
If you want normal animation then set frame and reduce alpha from 1.0 to 0.0 with duration.

Different animation duration for subviews of an UIView

I have the following code
[UIView animateWithDuration:2 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
mainPage.frame=CGRectMake(0, -[UIScreen mainScreen].bounds.size.width,[UIScreen mainScreen].bounds.size.height,[UIScreen mainScreen].bounds.size.width);
} completion:nil];
Is there any way to control the animation duration of the subviews of mainPage.
You can use UIView:animateKeyframesWithDuration then use UIView:addKeyframeWithRelativeStartTime to set its start time and duration
[UIView animateKeyframesWithDuration:2 delay:0 options:0 animations:^{
[UIView addKeyframeWithRelativeStartTime:0.32 relativeDuration:0.68 animations:^{
view.frame = frame;
}];
[UIView addKeyframeWithRelativeStartTime:0.5 relativeDuration:1 animations:^{
subview.frame = frame2;
}];
} completion:^(BOOL finished) {
}];
If you want the subviews to animate with a different duration then you'll need to animate each of them separately. You can loop through the mainPage.subviews array and issue an animateWithDuration:delay:options:animations:completion: call to each subview in turn, each with a different duration.

Lag between 2 animations

I am trying to animate one of my image form bottom to Top of my screen , for that i am implementing an animation that the current width and height of image will become half during the transition stage and will take its original size once animation completes.
The issue is once the 1st animation is done it hold's for a while and then starts another animation , i want a smooth animation .
Here is the code :
[UIView animateWithDuration:1.0
delay:0.5
options:UIViewAnimationOptionTransitionCurlUp
animations:^{
[_myImageView setFrame:CGRectMake(20.0, 220.0, currentframe.size.width/2, currentframe.size.height/2)];
} completion:^(BOOL finished)
{
if (finished)
{
[UIView animateWithDuration:1.0
delay:0
options:UIViewAnimationOptionBeginFromCurrentState
animations:^{
[_myImageView setFrame:CGRectMake(20.0, 20.0, currentframe.size.width, currentframe.size.height)];
} completion:^(BOOL finished) {
if (finished) {
NSLog(#"2 nd log ");
}
}];
NSLog(#"animation fisnished !!");
}
}];
What should be done ?
try this:
[UIView animateWithDuration:1.0
delay:0
options:UIViewAnimationOptionCurveLinear// use CurveLinear option
animations:^{
} completion:^(BOOL finished) {
}];

Resources