Kargol
Kargol

Reputation: 113

Why WKWebView doesn't apear in screen ? ( objective c )

I'm trying to add a UIView and WKWebView in a ViewController , I added programmatically with constraints.

UIView is showing and positioning well without any problem but WKWebView appear only for 0,5 seconds and then disappears. Is possible that if WKWebView is empty don't appear at the screen even if I set a width and height ?

Can you help me to find the error ?

ths

#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

Upvotes: 1

Views: 84

Answers (1)

shubham
shubham

Reputation: 631

If WKWebView is empty then it didn't show to the screen even if you set all the constraints.

Upvotes: 1

Related Questions