Search code examples
objective-cnstimernstimeinterval

Best way to show a UIView for a duration and hide it for an interval


I'm making an application in xcode. I need to show an ad in a UIView for while and hide it after that. For eg. I need to show the UIView for like 15 seconds and hide it for like 30 seconds. What is the best way to do this? Will 2 NSTimers do the job? Please help.


Solution

  • ViewController.m
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        [self performSelector:@selector(POPUpshow:) withObject:self afterDelay:0.5];
        }
    
    -(void)POPUpshow:(id)sender
    {
        PopUpview=[[UIView alloc]initWithFrame:CGRectMake(0, 50, 320, 430)];
        [PopUpview setBackgroundColor:[UIColor yellowColor]];
        [self.view addSubview:PopUpview];
        PopUpview.hidden=NO;
    
        [self performSelector:@selector(popupHide) withObject:self afterDelay:1];
    
    }
    
    -(void)popupHide{
        PopUpview.hidden=YES;
    }
    

    hope it helps