Open Ljmedia opened 7 years ago
Update addViewController method to make it work in ios11 :
(void)addViewController:(RTWalkthroughPageViewController *)vc {
[self.controllers addObject:vc]; [self addChildViewController:vc]; [vc didMoveToParentViewController:self];
if ([vc respondsToSelector:@selector(setDelegate:)]) vc.delegate = self;
// Setup the viewController view
vc.view.translatesAutoresizingMaskIntoConstraints = NO; [self.scrollview addSubview:vc.view];
// Constraints
NSDictionary metrics = @{@"w":@(vc.view.bounds.size.width),@"h":@(vc.view.bounds.size.height)}; NSDictionary viewsDict = @{@"view":vc.view, @"container": self.scrollview}; // - Generic cnst [self.scrollview addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[view(==container)]" options:0 metrics:metrics views:viewsDict]]; [self.scrollview addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[view(==container)]" options:0 metrics:metrics views:viewsDict]]; [self.scrollview addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-0-[view]|" options:0 metrics:nil views:viewsDict]];
// cnst for position: 1st element
if (self.controllers.count == 1) { [self.scrollview addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-0-[view]" options:0 metrics:nil views:@{@"view":vc.view}]];
// cnst for position: other elements
} else{
UIViewController *previousVC = self.controllers[self.controllers.count-2];
UIView *previousView = previousVC.view;
[self.scrollview addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[previousView]-0-[view]" options:0 metrics:nil views:@{@"previousView":previousView, @"view":vc.view}]];
if (self.lastViewConstraint) {
[self.scrollview removeConstraints:self.lastViewConstraint];
}
self.lastViewConstraint = [NSLayoutConstraint constraintsWithVisualFormat:@"H:[view]-0-|" options:0 metrics:nil views:@{@"view":vc.view}];
[self.scrollview addConstraints:self.lastViewConstraint];
} }
Also change constraints in viewDidLoad to :
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-0-[scrollview]-0-|" options:0 metrics:nil views:@{@"scrollview":self.scrollview}]];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-0-[scrollview]-0-|" options:0 metrics:nil views:@{@"scrollview":self.scrollview}]];
(not sure if the latter is necessary, but did it anyway to match constraints from original Walkthrough on which this project is based on).
Hello,
the project is compiling in Xcode 9, but it seems there is an issue with some constraints.
Best regards, Lars