Skip to content

Commit

Permalink
[Catalog] Fix Tabs example for rotation (#2019)
Browse files Browse the repository at this point in the history
* [Catalog] Fix Tabs example for rotation

When the last tab was selected and the scroll view was all the way to
the right, rotating the device from portrait to landscape would cause
the scroll view to reposition itself. This resulted in half of each of
the two screens being visible.

* Marking size unused

* Fixing swift example. Unmarking "size" as unused
  • Loading branch information
Robert Moore authored and willlarche committed Sep 21, 2017
1 parent d200d6c commit 017f86f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
Expand Up @@ -268,6 +268,16 @@ - (UIStatusBarStyle)preferredStatusBarStyle {
return UIStatusBarStyleLightContent;
}

- (void)viewWillTransitionToSize:(CGSize)size
withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
[coordinator animateAlongsideTransition:
^(__unused id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
// Update the scrollView position so that the selected view is entirely visible
[self tabBar:self.tabBar didSelectItem:self.tabBar.selectedItem];
} completion:nil];
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
}

@end

@implementation TabBarIconExample (CatalogByConvention)
Expand Down
Expand Up @@ -224,6 +224,15 @@ extension TabBarIconSwiftExample {
override var childViewControllerForStatusBarStyle: UIViewController? {
return appBar.headerViewController
}

override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
coordinator.animate(alongsideTransition: { (_) in
if let selectedItem = self.tabBar.selectedItem {
self.tabBar(self.tabBar, didSelect: selectedItem)
}
}, completion: nil)
super.viewWillTransition(to: size, with: coordinator)
}
}

// MARK: - Catalog by convention
Expand Down

0 comments on commit 017f86f

Please sign in to comment.