Я пытаюсь добавить UIView и WKWebView в ViewController, я добавил программно с ограничениями.
UIView хорошо показывает и позиционирует без проблем, но WKWebView появляется только на 0,5 секунды, а затем исчезает. Возможно ли, что если WKWebView пуст, не появиться на экране, даже если я установил ширину и высоту?
Можете ли вы помочь мне найти ошибку?
тыс
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
NSMutableArray *arrayContraints = [[NSMutableArray alloc] init];
[super viewDidLoad];
self.dialogView = [[UIView alloc] initWithFrame:CGRectZero];
self.panelWebView = [[WKWebView alloc] initWithFrame:CGRectZero];
_dialogView.backgroundColor = UIColor.redColor;
_panelWebView.backgroundColor = UIColor.greenColor;
[self.view addSubview:_panelWebView];
[self.view addSubview:_dialogView];
[self.dialogView setTranslatesAutoresizingMaskIntoConstraints:NO];
[self.panelWebView setTranslatesAutoresizingMaskIntoConstraints:NO];
[arrayContraints addObject: [NSLayoutConstraint constraintWithItem: self.dialogView
attribute: NSLayoutAttributeHeight
relatedBy: NSLayoutRelationEqual
toItem: nil
attribute: NSLayoutAttributeNotAnAttribute
multiplier: 1.0
constant: 200]];
[arrayContraints addObject: [NSLayoutConstraint constraintWithItem: self.dialogView
attribute: NSLayoutAttributeWidth
relatedBy: NSLayoutRelationEqual
toItem: nil
attribute: NSLayoutAttributeNotAnAttribute
multiplier: 1.0
constant: 100]];
[arrayContraints addObject: [NSLayoutConstraint constraintWithItem: self.dialogView
attribute: NSLayoutAttributeLeading
relatedBy: NSLayoutRelationEqual
toItem: self.dialogView.superview
attribute: NSLayoutAttributeLeading
multiplier: 1.0
constant: 80]];
[arrayContraints addObject: [NSLayoutConstraint constraintWithItem: self.dialogView
attribute: NSLayoutAttributeTop
relatedBy: NSLayoutRelationEqual
toItem: self.dialogView.superview
attribute: NSLayoutAttributeTop
multiplier: 1.0
constant: 80]];
[arrayContraints addObject: [NSLayoutConstraint constraintWithItem: self.panelWebView
attribute: NSLayoutAttributeWidth
relatedBy: NSLayoutRelationEqual
toItem: nil
attribute: NSLayoutAttributeNotAnAttribute
multiplier: 1.0
constant: 100]];
[arrayContraints addObject: [NSLayoutConstraint constraintWithItem: self.panelWebView
attribute: NSLayoutAttributeHeight
relatedBy: NSLayoutRelationEqual
toItem: nil
attribute: NSLayoutAttributeNotAnAttribute
multiplier: 1.0
constant: 100]];
[arrayContraints addObject: [NSLayoutConstraint constraintWithItem: self.panelWebView
attribute: NSLayoutAttributeTop
relatedBy: NSLayoutRelationEqual
toItem: self.panelWebView.superview
attribute: NSLayoutAttributeTop
multiplier: 1.0
constant: 80]];
[arrayContraints addObject: [NSLayoutConstraint constraintWithItem: self.panelWebView
attribute: NSLayoutAttributeLeading
relatedBy: NSLayoutRelationEqual
toItem: self.panelWebView.superview
attribute: NSLayoutAttributeLeading
multiplier: 1.0
constant: 260]];
[NSLayoutConstraint activateConstraints: arrayContraints];
[self.dialogView layoutIfNeeded];
[self.panelWebView layoutIfNeeded];
[self.dialogView.superview layoutIfNeeded];
}
@end