Search code examples
iosuitableviewuiviewuiviewanimationuiviewanimationtransition

Repeat Fade Effect not working


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


Solution

  • 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];