iOS-弹出视图或者限制时间消失

一.弹出视图

   1.声明相关属性和代理
        
        @property(nonatomic,strong)UIView *bgView;
        @property(nonatomic,strong)UIView *PopView;
    
    2.弹出视图
         self.bgView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT)];
        self.bgView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
        [self.view addSubview:self.bgView];
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapClick:)];
        tap.delegate = self;
        [self.bgView addGestureRecognizer:tap];
        
        self.PopView = self.PopView = [[UIView alloc]initWithFrame:CGRectMake(40, HEIGHT/6, WIDTH-80, HEIGHT/1.7)];
        self.PopView.backgroundColor = WHITECOLOR;
        self.PopView.layer.cornerRadius = 3;
        [self.bgView addSubview:self.PopView];
        
       NSArray *arr = @[@"七天无理由退货",@"质量问题",@"发票问题",@"未按约定时间发货",@"其他问题"];
for (int i = 0; i < arr.count; i++) {
        UIButton *warnBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        warnBtn.frame = CGRectMake(20, 40+i*(HEIGHT/13+15), WIDTH-80-40, HEIGHT/13);
        warnBtn.layer.cornerRadius = 3;
        warnBtn.clipsToBounds = YES;
        warnBtn.tag = i+1992;
        warnBtn.adjustsImageWhenHighlighted = NO;
        warnBtn.layer.borderColor = TEXTTINTCOLOR.CGColor;
        warnBtn.layer.borderWidth = 1.2;
        warnBtn.layer.masksToBounds = YES;
        [warnBtn setTitle:arr[i] forState:UIControlStateNormal];
        [warnBtn setTitleColor:TEXTCOLOR forState:UIControlStateNormal];
        warnBtn.titleLabel.font = [UIFont systemFontOfSize:16];
        [warnBtn addTarget:self action:@selector(warnBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [self.PopView addSubview:warnBtn];
}

    }    

    - (void)tapClick:(UITapGestureRecognizer *)sender{
        if (sender.numberOfTapsRequired== 1) {
            [_bgView removeFromSuperview];
        }
    }

二.限制时间
         _timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timeChange:) userInfo:nil repeats:NO];
                    
         _currentView = [[UIView alloc]initWithFrame:CGRectMake(20, 80, WIDTH-40, 30)];
         _currentView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.6];
    //                currentView.alpha =0.9;
         [self.view addSubview:_currentView];
         UILabel *lab = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, WIDTH-40, 30)];
         lab.text = @"当前已是最新版本";
         lab.textColor = WHITECOLOR;
         lab.font = [UIFont systemFontOfSize:10];
         lab.textAlignment = NSTextAlignmentCenter;
         [_currentView addSubview:lab];


  - (void)timeChange:(NSTimer *)sender{
        [UIView animateWithDuration:1 animations:^{
            [_currentView removeFromSuperview];

      }];
  }

你可能感兴趣的:(iOS-弹出视图或者限制时间消失)