UIAlertView 自动消失

- (void)viewDidLoad {
        [super viewDidLoad];
    
    self.view.backgroundColor =  [UIColor blackColor];
    self.imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, CGRectGetWidth([UIScreen mainScreen].bounds), CGRectGetHeight([UIScreen mainScreen].bounds))];
    
    _imageView.image = [UIImage imageNamed:@"logo.jpg"];
    [self.view addSubview:_imageView];
    
    _show = [[UIButton alloc]initWithFrame:CGRectMake(50, 50, 50, 50)];
    _show.backgroundColor = [UIColor lightGrayColor];

    [self.view addSubview:_show];
    [_show addTarget:self action:@selector(add:) forControlEvents:(UIControlEventTouchUpInside)];
 
}
-(void)add:(UIButton *)sender
{
    
    _alert = [[UIAlertView alloc]initWithTitle:@"Test" message:@"这是测试" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:nil, nil];

    
    [_alert show];
    NSTimer *timer;
    
    timer = [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(doTime) userInfo:nil repeats:NO];
     
    }```

-(void)doTime

{

//alert过1秒自动消失

[_alert dismissWithClickedButtonIndex:0 animated:YES];

}

你可能感兴趣的:(UIAlertView 自动消失)