Skip to content

Commit

Permalink
fix(splashscreen): positioning after rotation (#1315)
Browse files Browse the repository at this point in the history
Co-authored-by: Michael Goffioul <michael.goffioul@gmail.com>
  • Loading branch information
dpogue and goffioul committed Apr 24, 2023
1 parent fd93156 commit 1a5cd45
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion CordovaLib/Classes/Public/CDVViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -501,18 +501,36 @@ - (void)createLaunchView
webViewBounds.origin = self.view.bounds.origin;

UIView* view = [[UIView alloc] initWithFrame:webViewBounds];
view.translatesAutoresizingMaskIntoConstraints = NO;
[view setAlpha:0];

NSString* launchStoryboardName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"UILaunchStoryboardName"];
if (launchStoryboardName != nil) {
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:launchStoryboardName bundle:[NSBundle mainBundle]];
UIViewController* vc = [storyboard instantiateInitialViewController];
[self addChildViewController:vc];

[view addSubview:vc.view];
UIView* imgView = vc.view;
imgView.translatesAutoresizingMaskIntoConstraints = NO;
[view addSubview:imgView];

[NSLayoutConstraint activateConstraints:@[
[NSLayoutConstraint constraintWithItem:imgView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:view attribute:NSLayoutAttributeWidth multiplier:1 constant:0],
[NSLayoutConstraint constraintWithItem:imgView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:view attribute:NSLayoutAttributeHeight multiplier:1 constant:0],
[NSLayoutConstraint constraintWithItem:imgView attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:view attribute:NSLayoutAttributeCenterY multiplier:1 constant:0],
[NSLayoutConstraint constraintWithItem:imgView attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:view attribute:NSLayoutAttributeCenterX multiplier:1 constant:0]
]];
}

self.launchView = view;
[self.view addSubview:view];

[NSLayoutConstraint activateConstraints:@[
[NSLayoutConstraint constraintWithItem:view attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeWidth multiplier:1 constant:0],
[NSLayoutConstraint constraintWithItem:view attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeHeight multiplier:1 constant:0],
[NSLayoutConstraint constraintWithItem:view attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterY multiplier:1 constant:0],
[NSLayoutConstraint constraintWithItem:view attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterX multiplier:1 constant:0]
]];
}

- (void)createGapView
Expand Down

0 comments on commit 1a5cd45

Please sign in to comment.