Closed akotulu closed 6 years ago
Hey, thank you, I'm happy you find it useful. I have no intention of porting it to swift or adding any more features, at least for now, but I will happily accept reasonable pull request.
I am curios why the demo project isn't building for you though, they both seem to be fine on my side. It would be great if you could give me some more details on that.
Ok, tested it with pod try and everything works fine. Im used to just download the project as a zip, but this way it wont compile :)
Well I found a issue which I tried to fix but failed. My view controllers are set up using AutoLayout and when I insert a new controller to the pageViewController using method
open func insertPages(at indexes: IndexSet!, animated: Bool, completion: (() -> Swift.Void)!)
view isn't displayed properly.
Here are the screenshots. Wrong - bottom and top are off Correct - stretched properly
Current solution I found is to add the view to the hierarchy and then remove it before calling insert function like so
self.containerView.insertSubview(viewController.view, at: 0)
viewController.view.removeFromSuperview()
self.viewControllers.insert(viewController, at: 0)
self.pageViewController.insertPages(at: IndexSet(integer: 0), animated: false, completion: nil)
This way the view is displayed correctly.
I'm thinking it might be caused by certain constraints being broken when first inserting the page because of zero frames. Can you please send me a small demo project where this happens so I have something to debug on top of ?
Hey!
Put together a small project from my current one. Press the add button twice to see the second view controller is smaller and bottom toolbar isn't where it should.
Hey, sorry for the late reply. That link you posted seems to be broken now, have you been able to figure out the issue in the mean time ?
Hey, checked the link and it works and I haven't found a solution. Can you elaborate, why isn't this link working, what browser are you using and where do you request this file? Does wget produce the same output?
I'm guessing it is this line which messes everything up
CATransform3D previousTransform = viewController.view.layer.transform;
[self _setAnimatableSublayerTransform:CATransform3DIdentity forViewController:viewController];
Edit:
Finally after many hours I have finally figured it out. The problem isn't with the Transform, but close in same function.
// Finally, trigger appearance callbacks and new frame
if(visible && ![self.visibleControllers containsObject:viewController]) {
[self.visibleControllers addObject:viewController];
//[viewController beginAppearanceTransition:YES animated:YES];
[viewController.view setFrame:nextFrame];
//[viewController endAppearanceTransition];
if([self.delegate respondsToSelector:@selector(pageViewController:didShowViewController:atIndex:)]) {
[self.delegate pageViewController:self didShowViewController:viewController atIndex:pageIndex];
}
} else if(!visible && [self.visibleControllers containsObject:viewController]) {
[self.visibleControllers removeObject:viewController];
//[viewController beginAppearanceTransition:NO animated:NO];
[viewController.view setFrame:nextFrame];
//[viewController endAppearanceTransition];
if([self.delegate respondsToSelector:@selector(pageViewController:didHideViewController:atIndex:)]) {
[self.delegate pageViewController:self didHideViewController:viewController atIndex:pageIndex];
}
} else {
[viewController.view setFrame:nextFrame];
}
You are calling these methods too late, they have to be called before any animation.
[viewController beginAppearanceTransition:NO animated:NO];
[viewController endAppearanceTransition];
I commented out both of those transitions from your code and added them to my top function like so and everything works like intended.
viewController.beginAppearanceTransition(true, animated: true)
self.pageViewController.insertPages(at: IndexSet(integer: 0), animated: false, completion: {
self.pageViewController.navigateToPage(at: 0, animated: true, completion: nil)
})
viewController.endAppearanceTransition()
If you have time, would be awesome if you could fix this issue. Also currently there is no way to use UIPageControl, cause of missing delegate willShowViewController
. Currently available didShowViewController
report too late and animation looks out of sync - page animation ends and dot starts to animate.
I'm not entirely following your theory as I don't understand why appearance transition calls would affect view controller frames. Debugging your project also seems to reveal that both view controllers have equal sizes
▿ 2 elements
▿ 0 : <PageController.LumenViewController: 0x7fcba450dab0>
▿ 1 : <PageController.AlcoViewController: 0x7fcba450b3a0>
(lldb) po self.viewControllers.first?.view.frame
▿ Optional<CGRect>
▿ some : (0.0, 0.0, 1024.0, 704.0)
▿ origin : (0.0, 0.0)
- x : 0.0
- y : 0.0
▿ size : (1024.0, 704.0)
- width : 1024.0
- height : 704.0
(lldb) po self.viewControllers.last?.view.frame
▿ Optional<CGRect>
▿ some : (1074.0, 0.0, 1024.0, 704.0)
▿ origin : (1074.0, 0.0)
- x : 1074.0
- y : 0.0
▿ size : (1024.0, 704.0)
- width : 1024.0
- height : 704.0
What I also did is to trim down your view controller to their most basic form and found that their frames are yet again correct. You can find my modifications on your sample project here
All of these lead me to believe there's something wrong within your project and not the pageViewController.
As for the other thing you mentioned ...
Also currently there is no way to use UIPageControl, cause of missing delegate willShowViewController. Currently available didShowViewController report too late and animation looks out of sync - page animation ends and dot starts to animate.
I would suggest you hook your UIPageControl to one the following pageViewController delegate methods
- (void)pageViewController:(SCPageViewController *)pageViewController
didNavigateToOffset:(CGPoint)offset;
- (void)pageViewController:(SCPageViewController *)pageViewController
didNavigateToPageAtIndex:(NSUInteger)pageIndex;
and the @property (nonatomic, readonly) NSUInteger currentPage;
property
If you run my initial project in simulator or device of your choosing and press add button on top, then scroll to the new view controller. Look at the element positions, they are not placed correctly. The view size is same I know, problem is where the elements are. I'm guessing calling these methods inside animation will interrupt constraint calculation. As docs indicate, constraint calculation is long multipart process.
Right, so as far as I can tell all your problems are caused by constraints setup to follow layout margins, quite a few of them actually. I've put together this video that will show you how to modify them and get everything working properly.
Nice one, good find 👍 Seems I was wrong all along, thank you for sorting this issue out, had problems with this before. Missed this feature existed and is enabled by default. Initial iOS versions when margins where introduced they where optional. Well if you can, maybe update docs, someone else could have this problem.
Hei!
Really nice work, I searched for a library that has insert and delete view controllers built in, but found none and I searched for days. Then I found yours, works like a charm and has every needed delegate included with some sugar. I mean if you want more stars make a swift version. You'd be only one to support this mandatory feature that everyone else seems to forget. All other libraries take a static array and only support reloadAll which isn't smooth transition.
Would be nice if you included infinite paging, last page returns to first.
Btw example project didn't compile :)
👍