我是iOS编程的新手,
我已经实现了UITableViewController并像弹出菜单一样在主页上获得了tableViewController设计,
在背面,我在主页和tableViewController之间添加了模糊效果。
模糊效果视图和UITableView均作为子视图添加到主屏幕中。
这是我的问题:
当我验证tableViewController的UITextfields时,alertController出现在模糊效果和tableViewController的背面,我需要在tableViewController之上。
如何获取?
我在下面的代码中使用了模糊效果和tableView:
UIVisualEffect *blurEffect;
blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
visualEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
visualEffectView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
[[UIApplication sharedApplication].keyWindow addSubview:visualEffectView];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
viewaccept = (AcceptViewController *)[storyboard instantiateViewControllerWithIdentifier:@"AcceptViewController"];
[viewaccept willMoveToParentViewController:self];
CGRect screen = [[UIScreen mainScreen] bounds];
CGRect newFrame = CGRectMake(0,screen.size.height/4, self.view.frame.size.width, 350);
UIEdgeInsets insets = UIEdgeInsetsMake(0,10,0,10);
viewaccept.view.frame = UIEdgeInsetsInsetRect(newFrame,insets);
CGRect splitframe = viewaccept.view.frame;
[viewaccept.view setFrame:splitframe];
[[UIApplication sharedApplication].keyWindow addSubview:viewaccept.view];
[self addChildViewController:viewaccept];
[viewaccept didMoveToParentViewController:self];
我使用下面的代码显示警报:
NSString *message = @"Email Id is already registered";
UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:message preferredStyle:UIAlertControllerStyleAlert];
[self presentViewController:alert animated:YES completion:nil];
int duration = 3; // duration in seconds
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, duration * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
[alert dismissViewControllerAnimated:YES completion:nil];
});
最佳答案
尝试这个
UIWindow* topWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
topWindow.rootViewController = [UIViewController new];
topWindow.windowLevel = UIWindowLevelAlert + 1;
UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"Title" message:@"Your Message" preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"OK",@"confirm") style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
// continue your work
// important to hide the window after work completed.
// this also keeps a reference to the window until the action is invoked.
topWindow.hidden = YES;
}]];
[topWindow makeKeyAndVisible];
[topWindow.rootViewController presentViewController:alert animated:YES completion:nil];
关于ios - 如何在Objective C中通过UIView获取UIAlertController?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48804127/