From 857c321ede7fa44b6821eefc7261602ef554fed7 Mon Sep 17 00:00:00 2001 From: Ilter Cengiz Date: Sat, 21 Sep 2013 17:54:57 +0300 Subject: [PATCH] Bug fix for tabsView location --- ICViewPager/Controller/HostViewController.m | 3 ++ ICViewPager/ICViewPager/ViewPagerController.m | 45 ++++++++++++------- 2 files changed, 31 insertions(+), 17 deletions(-) diff --git a/ICViewPager/Controller/HostViewController.m b/ICViewPager/Controller/HostViewController.m index a364a48..b06b03a 100644 --- a/ICViewPager/Controller/HostViewController.m +++ b/ICViewPager/Controller/HostViewController.m @@ -71,6 +71,9 @@ - (CGFloat)viewPager:(ViewPagerController *)viewPager valueForOption:(ViewPagerO case ViewPagerOptionCenterCurrentTab: return 0.0; break; + case ViewPagerOptionTabLocation: + return 1.0; + break; default: break; } diff --git a/ICViewPager/ICViewPager/ViewPagerController.m b/ICViewPager/ICViewPager/ViewPagerController.m index fcf0af5..f9521ad 100644 --- a/ICViewPager/ICViewPager/ViewPagerController.m +++ b/ICViewPager/ICViewPager/ViewPagerController.m @@ -88,6 +88,7 @@ @interface ViewPagerController () origPageScrollViewDelegate; @property UIScrollView *tabsView; +@property UIView *contentView; @property NSMutableArray *tabs; @property NSMutableArray *contents; @@ -123,6 +124,24 @@ - (void)viewDidLoad { [self reloadData]; } +- (void)viewWillLayoutSubviews { + + CGRect frame; + + frame = _tabsView.frame; + frame.origin.x = 0.0; + frame.origin.y = self.tabLocation ? 0.0 : self.view.frame.size.height - self.tabHeight; + frame.size.width = self.view.bounds.size.width; + frame.size.height = self.tabHeight; + _tabsView.frame = frame; + + frame = _contentView.frame; + frame.origin.x = 0.0; + frame.origin.y = self.tabLocation ? self.tabHeight : 0.0; + frame.size.width = self.view.bounds.size.width; + frame.size.height = self.view.frame.size.height - self.tabHeight; + _contentView.frame = frame; +} - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; @@ -311,10 +330,7 @@ - (void)reloadData { } // Add tabsView - _tabsView = [[UIScrollView alloc] initWithFrame:CGRectMake(0.0, - self.tabLocation ? 0.0 : self.view.frame.size.height - self.tabHeight, - self.view.frame.size.width, - self.tabHeight)]; + _tabsView = [[UIScrollView alloc] initWithFrame:CGRectMake(0.0, 0.0, self.view.frame.size.width, self.tabHeight)]; _tabsView.autoresizingMask = UIViewAutoresizingFlexibleWidth; _tabsView.backgroundColor = self.tabsViewBackgroundColor; _tabsView.showsHorizontalScrollIndicator = NO; @@ -345,24 +361,19 @@ - (void)reloadData { _tabsView.contentSize = CGSizeMake(contentSizeWidth, self.tabHeight); // Add contentView - UIView *pageView = [self.view viewWithTag:kPageViewTag]; + _contentView = [self.view viewWithTag:kPageViewTag]; - if (!pageView) { + if (!_contentView) { - pageView = _pageViewController.view; - pageView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; - pageView.backgroundColor = self.contentViewBackgroundColor; - pageView.bounds = self.view.bounds; - pageView.tag = kPageViewTag; + _contentView = _pageViewController.view; + _contentView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; + _contentView.backgroundColor = self.contentViewBackgroundColor; + _contentView.bounds = self.view.bounds; + _contentView.tag = kPageViewTag; - [self.view insertSubview:pageView atIndex:0]; + [self.view insertSubview:_contentView atIndex:0]; } - CGRect frame = pageView.frame; - frame.size.height = self.view.frame.size.height - self.tabHeight; - frame.origin.y = self.tabLocation ? self.tabHeight : 0.0; - pageView.frame = frame; - // Set first viewController UIViewController *viewController;