From 8a2efcd95f675f058be95ae58ee180dccde5d34e Mon Sep 17 00:00:00 2001 From: Martin Barreto Date: Fri, 10 Apr 2015 03:49:09 -0300 Subject: [PATCH] fix issues #12 & #6 --- XLPagerTabStrip.xcodeproj/project.pbxproj | 4 +- .../XLBarPagerTabStripViewController.m | 4 -- .../XLPagerTabStripViewController.m | 59 ++++++++++++++----- .../XLTwitterPagerTabStripViewController.m | 8 ++- 4 files changed, 51 insertions(+), 24 deletions(-) diff --git a/XLPagerTabStrip.xcodeproj/project.pbxproj b/XLPagerTabStrip.xcodeproj/project.pbxproj index 6ec6a91..867394f 100644 --- a/XLPagerTabStrip.xcodeproj/project.pbxproj +++ b/XLPagerTabStrip.xcodeproj/project.pbxproj @@ -446,7 +446,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 8.1; + IPHONEOS_DEPLOYMENT_TARGET = 7.1; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -481,7 +481,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 8.1; + IPHONEOS_DEPLOYMENT_TARGET = 7.1; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; VALIDATE_PRODUCT = YES; diff --git a/XLPagerTabStrip/XL/Controllers/XLBarPagerTabStripViewController.m b/XLPagerTabStrip/XL/Controllers/XLBarPagerTabStripViewController.m index ddaca23..8730822 100644 --- a/XLPagerTabStrip/XL/Controllers/XLBarPagerTabStripViewController.m +++ b/XLPagerTabStrip/XL/Controllers/XLBarPagerTabStripViewController.m @@ -30,16 +30,12 @@ - (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; - if (self) { - } return self; } - (instancetype)initWithCoder:(NSCoder *)coder { self = [super initWithCoder:coder]; - if (self) { - } return self; } diff --git a/XLPagerTabStrip/XL/Controllers/XLPagerTabStripViewController.m b/XLPagerTabStrip/XL/Controllers/XLPagerTabStripViewController.m index 2cef2e5..22ae922 100644 --- a/XLPagerTabStrip/XL/Controllers/XLPagerTabStripViewController.m +++ b/XLPagerTabStrip/XL/Controllers/XLPagerTabStripViewController.m @@ -37,6 +37,7 @@ CGFloat _lastContentOffset; NSUInteger _pageBeforeRotate; NSArray * _originalPagerTabStripChildViewControllers; + CGSize _lastSize; } @synthesize currentIndex = _currentIndex; @@ -101,10 +102,26 @@ -(void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; - [self.containerView setContentOffset:CGPointMake([self pageOffsetForChildIndex:self.currentIndex], 0) animated:NO]; + _lastSize = self.containerView.bounds.size; } +-(void)viewDidAppear:(BOOL)animated +{ + [super viewDidAppear:animated]; + [self updateIfNeeded]; +} + +-(void)viewDidLayoutSubviews +{ + [super viewDidLayoutSubviews]; + [self updateIfNeeded]; + if ([[[UIDevice currentDevice] systemVersion] compare:@"8.0" options:NSNumericSearch] == NSOrderedAscending){ + // SYSTEM_VERSION_LESS_THAN 8.0 + [self.view layoutSubviews]; + } +} + #pragma mark - move to another view controller -(void)moveToViewControllerAtIndex:(NSUInteger)index @@ -177,6 +194,15 @@ #pragma mark - Helpers +-(void)updateIfNeeded +{ + if (!CGSizeEqualToSize(_lastSize, self.containerView.bounds.size)){ + _lastSize = self.containerView.bounds.size; + [self.containerView setContentOffset:CGPointMake([self pageOffsetForChildIndex:self.currentIndex], 0) animated:NO]; + [self updateContent]; + } +} + -(XLPagerTabStripDirection)scrollDirection { if (self.containerView.contentOffset.x > _lastContentOffset){ @@ -348,9 +374,9 @@ _pagerTabStripChildViewControllers = self.dataSource ? [self.dataSource childViewControllersForPagerTabStripViewController:self] : @[]; self.containerView.contentSize = CGSizeMake(CGRectGetWidth(self.containerView.bounds) * _pagerTabStripChildViewControllers.count, self.containerView.contentSize.height); if (self.currentIndex >= _pagerTabStripChildViewControllers.count){ - self.currentIndex = _pagerTabStripChildViewControllers.count; - [self.containerView setContentOffset:CGPointMake([self pageOffsetForChildIndex:(_pagerTabStripChildViewControllers.count - 1)], 0) animated:NO]; + self.currentIndex = _pagerTabStripChildViewControllers.count - 1; } + [self.containerView setContentOffset:CGPointMake([self pageOffsetForChildIndex:self.currentIndex], 0) animated:NO]; [self updateContent]; } } @@ -392,25 +418,28 @@ #pragma mark - Orientation +- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id)coordinator +{ + [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator]; + _pageBeforeRotate = self.currentIndex; + __typeof__(self) __weak weakSelf = self; + + UIInterfaceOrientation fromOrientation = [[UIApplication sharedApplication] statusBarOrientation]; + [coordinator animateAlongsideTransition:nil + completion:^(id context) { + [weakSelf didRotateFromInterfaceOrientation:fromOrientation]; + }]; +} + -(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { _pageBeforeRotate = self.currentIndex; } --(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration +-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { self.currentIndex = _pageBeforeRotate; - self.containerView.contentSize = CGSizeMake(CGRectGetWidth(self.containerView.bounds) * self.pagerTabStripChildViewControllers.count, self.containerView.contentSize.height); - [self.containerView setContentOffset:CGPointMake([self pageOffsetForChildIndex:_pageBeforeRotate], 0) animated:NO]; - - [self updateContent]; -} - --(void)viewDidLayoutSubviews -{ - [super viewDidLayoutSubviews]; - [self updateContent]; - + [self updateIfNeeded]; } diff --git a/XLPagerTabStrip/XL/Controllers/XLTwitterPagerTabStripViewController.m b/XLPagerTabStrip/XL/Controllers/XLTwitterPagerTabStripViewController.m index ad49141..e8cec3c 100644 --- a/XLPagerTabStrip/XL/Controllers/XLTwitterPagerTabStripViewController.m +++ b/XLPagerTabStrip/XL/Controllers/XLTwitterPagerTabStripViewController.m @@ -46,6 +46,10 @@ if (!self.navigationView.superview) { self.navigationItem.titleView = self.navigationView; } + if (self.navigationItem.titleView == self.navigationView){ + [self.navigationView addObserver:self forKeyPath:@"frame" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context:0]; + [self.navigationView setFrame:CGRectMake(0, 0, CGRectGetWidth(self.navigationController.navigationBar.frame) , CGRectGetHeight(self.navigationController.navigationBar.frame))]; + } if (!self.navigationScrollView.superview) { [self.navigationView addSubview:self.navigationScrollView]; } @@ -60,8 +64,6 @@ -(void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; - [self.navigationView setFrame:CGRectMake(0, 0, CGRectGetWidth(self.navigationController.navigationBar.frame) , CGRectGetHeight(self.navigationController.navigationBar.frame))]; - [self.navigationView addObserver:self forKeyPath:@"frame" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context:0]; } @@ -77,7 +79,7 @@ -(void)setIsProgressiveIndicator:(BOOL)isProgressiveIndicator { - [super setIsProgressiveIndicator:YES]; + super.isProgressiveIndicator = YES; }