这是我在UILabel上从UITapGestureRecognizer调用的方法.
- (IBAction)labelTaped:(UITapGestureRecognizer *)sender { if (sender.state == UIGestureRecognizerStateEnded) { CGRect frame = CGRectNull; Nsstring *message = nil; // ... // some code /// ... if (message) { // show info alert __weak __typeof(self)weakSelf = self; UIAlertController* alert = [UIAlertController alertControllerWithTitle:nil message:message preferredStyle:UIAlertControllerStyleActionSheet]; UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"alert_ok",@" - ") style:UIAlertActionStyleCancel handler:^(UIAlertAction * action) { if ([weakSelf.dismissAlertTimer isValID]) { [weakSelf.dismissAlertTimer invalIDate]; } }]; [alert addAction:cancelAction]; UIPopoverPresentationController *popoverController = alert.popoverPresentationController; popoverController.sourceRect = frame; popoverController.sourceVIEw = sender.vIEw; [self.mainController presentVIEwController:alert animated:YES completion:^{ if ([weakSelf.dismissAlertTimer isValID]) { [weakSelf.dismissAlertTimer invalIDate]; } weakSelf.dismissAlertTimer = [NSTimer scheduledTimerWithTimeInterval:5.0 target:weakSelf selector:@selector(dismissAlertController) userInfo:nil repeats:NO]; }]; } }}- (voID)dismissAlertController { [self.mainController dismissVIEwControllerAnimated:YES completion:^{ // }];}解决方法 最简单的是这样的吗?
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Alert" message:@"message dismiss in 2 seconds" preferredStyle:UIAlertControllerStyleAlert];[self presentVIEwController:alertController animated:YES completion:nil];dispatch_after(dispatch_time(disPATCH_TIME_Now,(int64_t)(2.0 * NSEC_PER_SEC)),dispatch_get_main_queue(),^{ [alertController dismissVIEwControllerAnimated:YES completion:^{ // do something ? }];});
或者你的意思是你还想阻止用户在触发2秒之前点击取消按钮?
总结以上是内存溢出为你收集整理的ios – UIAlertController仅在2秒后解除全部内容,希望文章能够帮你解决ios – UIAlertController仅在2秒后解除所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)