Question

Following is my code, Used for showing some fade effect while adding the table on a sub view. Problem is that code works for the first time. After adding table, when I hit close the Sub view button table is removed. But when I hit the Button to add table again on subview fade effect doesn't work fine

 double delayInSeconds2 = 0.1;

        dispatch_time_t popTime2 = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds2 * NSEC_PER_SEC));
        dispatch_after(popTime2, dispatch_get_main_queue(), ^(void){


            self.otlTableRightView.frame=CGRectMake(100, 68, 300, 378);
            [self.otlTableRightView setAlpha:0.0];
            [self.otlRightFromView addSubview:self.otlTableRightView];


            [UIView beginAnimations:nil context:nil];
            [UIView setAnimationDuration:1.2];

            self.otlTableRightView.frame=CGRectMake(43, 68, 300, 378);

            [UIView commitAnimations];


            [UIView animateWithDuration:2.0 delay:0.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
                [self.otlTableRightView setAlpha:0.0];
            }completion:^(BOOL done){

            }];

        });

and I am using

[self.otlTableRightView removeFromSuperview];

to remove my table from my sub view

Was it helpful?

Solution 3

After some search, Finally I found something that works in my case. Here, otlTableRightView is the outlet for my UItableView

            self.otlTableRightView.alpha = 0;
            [UIView beginAnimations:@"fade in" context:nil];
            [UIView setAnimationDuration:2.0];
            self.otlTableRightView.alpha = 1.0;
            [UIView commitAnimations];

OTHER TIPS

If you want repeat animation you shouldn't removeFromSuperview your subview! Then all the repeat method does not matter.

You also may consider simpler solution for that kind of behavior:

[UIView animateWithDuration:0.5
                      delay:0.0
                    options:UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat | UIViewAnimationOptionCurveEaseInOut
                 animations:^{
                     [self.otlTableRightView setAlpha:0.0];
                 }
                 completion:^(BOOL done){
                [self.otlTableRightView setAlpha:2.0];
            }];

As you can see in option you can add multiple parameters.

To remove your table view with fade effect try this..Hope it wold work.

> [UIView animateWithDuration:1.0
>                       delay:0.0
>                     options: UIViewAnimationOptionCurveEaseInOut
>                  animations:^{
>                      [self.otlTableRightView setAlpha:0.0];
>                  }
>                  completion:^(BOOL done){
>                 [self.otlTableRightView removeFromSuperview];
>             }];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top