当我向keyWindow添加UIView时,viewController覆盖了alertController。这是代码。
- (void)touch {
UIWindow *currentWindow = [UIApplication sharedApplication].keyWindow;
UIView *viewhaha = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
viewhaha.backgroundColor = [UIColor redColor];
[currentWindow addSubview:viewhaha];
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"123" message:@"123" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"123" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
}];
[alertController addAction:action1];
[self presentViewController:alertController animated:YES completion:^{
}];
}
这是图像。 Image
你知道怎么解决吗?
答案 0 :(得分:1)
向public class StackWithMin extends Stack<Integer> {
private Stack<Integer> min;
public StackWithMin() {
min = new Stack<>();
}
public void push(int num) {
if (super.isEmpty()) {
min.push(num);
} else if (num <= min.peek()) {
min.push(num);
}
super.push(num);
}
public int min() {
return min.peek();
}
public Integer pop() {
if (super.peek() == min.peek()) {
min.pop();
}
return super.pop();
}
}
添加视图将涵盖任何未添加到window
并置于其上的视图。窗口图层是您可以添加内容的最上层。如果您希望将window
放在UIView
下方,则必须将UIAlertViewController
添加到UIView
UIViewController
的子视图中正在展示.view
。
答案 1 :(得分:1)
答案 2 :(得分:0)
将新的UIView添加到视图控制器而不是关键窗口。只需改变第4行
[currentWindow addSubview:viewhaha];
到
[self.view addSubview:viewhaha];
答案 3 :(得分:0)
- (void)touch {
UIViewController *currentTopVC = [self currentTopViewController];
UIView *viewhaha = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
viewhaha.backgroundColor = [UIColor redColor];
[currentTopVC.view addSubview:viewhaha];
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"123" message:@"123" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"123" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
}];
[alertController addAction:action1];
[currentTopVC presentViewController:alertController animated:YES completion:^{
}];
}
- (UIViewController *)currentTopViewController {
UIViewController *topVC = [[[[UIApplication sharedApplication] delegate] window] rootViewController];
while (topVC.presentedViewController)
{
topVC = topVC.presentedViewController;
}
return topVC;
}