From 1fcf200a6ea0aedae08d44421145a47c2d6d5ee3 Mon Sep 17 00:00:00 2001 From: pastorin Date: Wed, 8 Apr 2015 14:59:16 -0300 Subject: [PATCH] various changes --- XLPagerTabStrip.xcodeproj/project.pbxproj | 3 + XLPagerTabStrip/Demo/Storyboard.storyboard | 2 +- .../XLTwitterPagerTabStripViewController.m | 109 +++++++++++------- 3 files changed, 70 insertions(+), 44 deletions(-) diff --git a/XLPagerTabStrip.xcodeproj/project.pbxproj b/XLPagerTabStrip.xcodeproj/project.pbxproj index b7c850e..7782342 100644 --- a/XLPagerTabStrip.xcodeproj/project.pbxproj +++ b/XLPagerTabStrip.xcodeproj/project.pbxproj @@ -320,6 +320,7 @@ TargetAttributes = { 28B63A851A459F5900225C66 = { CreatedOnToolsVersion = 6.1.1; + DevelopmentTeam = 6F2G55XL63; }; 28B63A9E1A459F5900225C66 = { CreatedOnToolsVersion = 6.1.1; @@ -505,6 +506,7 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_IDENTITY = "iPhone Developer"; INFOPLIST_FILE = XLPagerTabStrip/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -515,6 +517,7 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_IDENTITY = "iPhone Developer"; INFOPLIST_FILE = XLPagerTabStrip/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_NAME = "$(TARGET_NAME)"; diff --git a/XLPagerTabStrip/Demo/Storyboard.storyboard b/XLPagerTabStrip/Demo/Storyboard.storyboard index b75b7a4..bfba753 100644 --- a/XLPagerTabStrip/Demo/Storyboard.storyboard +++ b/XLPagerTabStrip/Demo/Storyboard.storyboard @@ -1,5 +1,5 @@ - + diff --git a/XLPagerTabStrip/XL/Controllers/XLTwitterPagerTabStripViewController.m b/XLPagerTabStrip/XL/Controllers/XLTwitterPagerTabStripViewController.m index 5c6d648..432db33 100644 --- a/XLPagerTabStrip/XL/Controllers/XLTwitterPagerTabStripViewController.m +++ b/XLPagerTabStrip/XL/Controllers/XLTwitterPagerTabStripViewController.m @@ -13,7 +13,7 @@ @interface XLTwitterPagerTabStripViewController () -@property (nonatomic) IBOutlet UIView * navigationView; +@property (nonatomic) UIView * navigationView; @property (nonatomic) UIScrollView * navigationScrollView; @property (nonatomic) FXPageControl * navigationPageControl; @property (nonatomic, strong) NSMutableArray * navigationItemsViews; @@ -26,9 +26,8 @@ - (void)viewDidLoad { [super viewDidLoad]; - // Do any additional setup after loading the view. if (!self.navigationView.superview) { - [self.navigationController.navigationBar addSubview:self.navigationView]; + self.navigationItem.titleView = self.navigationView; } if (!self.navigationScrollView.superview) { [self.navigationView addSubview:self.navigationScrollView]; @@ -38,15 +37,18 @@ [self.navigationView addSubview:self.navigationPageControl]; } - _navigationScrollView.bounces = YES; - _navigationScrollView.scrollsToTop = NO; - _navigationScrollView.delegate = self; - _navigationScrollView.showsVerticalScrollIndicator = NO; - _navigationScrollView.showsHorizontalScrollIndicator = NO; - _navigationScrollView.pagingEnabled = YES; - _navigationScrollView.userInteractionEnabled = NO; - [_navigationScrollView setAlwaysBounceHorizontal:YES]; - [_navigationScrollView setAlwaysBounceVertical:NO]; + + UIBarButtonItem *flipButton = [[UIBarButtonItem alloc] + initWithTitle:@"Flip" + style:UIBarButtonItemStyleDone + target:self + action:nil]; + UIBarButtonItem *searchButton = [[UIBarButtonItem alloc] + initWithTitle:@"Flip" + style:UIBarButtonItemStyleDone + target:self + action:nil]; + self.navigationItem.rightBarButtonItems = [NSArray arrayWithObjects:flipButton, searchButton, nil]; [self reloadNavigatorContainerView]; } @@ -54,6 +56,7 @@ -(void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; + [self.navigationView setFrame:CGRectMake(0, 0, CGRectGetWidth(self.navigationController.navigationBar.frame) , CGRectGetHeight(self.navigationController.navigationBar.frame))]; [self setCurrentNavigationScrollViewOffset]; } @@ -75,6 +78,8 @@ if (_navigationView) return _navigationView; _navigationView = [[UIView alloc] init]; _navigationView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; + _navigationView.frame = CGRectMake(0, 0, CGRectGetWidth(self.navigationController.navigationBar.frame) - 16, CGRectGetHeight(self.navigationController.navigationBar.frame)); + [_navigationView setBackgroundColor:[UIColor redColor]]; return _navigationView; } @@ -83,6 +88,15 @@ if (_navigationScrollView) return _navigationScrollView; _navigationScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), 44)]; _navigationScrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; + _navigationScrollView.bounces = YES; + _navigationScrollView.scrollsToTop = NO; + _navigationScrollView.delegate = self; + _navigationScrollView.showsVerticalScrollIndicator = NO; + _navigationScrollView.showsHorizontalScrollIndicator = NO; + _navigationScrollView.pagingEnabled = YES; + _navigationScrollView.userInteractionEnabled = NO; + [_navigationScrollView setAlwaysBounceHorizontal:YES]; + [_navigationScrollView setAlwaysBounceVertical:NO]; return _navigationScrollView; } @@ -108,18 +122,28 @@ #pragma mark - XLPagerTabStripViewControllerDataSource +-(void)pagerTabStripViewController:(XLPagerTabStripViewController *)pagerTabStripViewController updateIndicatorToViewController:(UIViewController *)toViewController fromViewController:(UIViewController *)fromViewController +{ +// if (self.shouldUpdateButtonBarView){ +// NSUInteger newIndex = [self.pagerTabStripChildViewControllers indexOfObject:toViewController]; +// XLPagerTabStripDirection direction = XLPagerTabStripDirectionLeft; +// if (newIndex < [self.pagerTabStripChildViewControllers indexOfObject:fromViewController]){ +// direction = XLPagerTabStripDirectionRight; +// } +// [self.buttonBarView moveToIndex:newIndex animated:YES swipeDirection:direction]; +// } +} + -(void)pagerTabStripViewController:(XLPagerTabStripViewController *)pagerTabStripViewController updateIndicatorFromIndex:(NSInteger)fromIndex toIndex:(NSInteger)toIndex withProgressPercentage:(CGFloat)progressPercentage { - CGFloat distance = CGRectGetWidth(self.navigationScrollView.frame) / 2; - UIAccelerationValue xOffset = fromIndex < toIndex ? distance * fromIndex + distance * progressPercentage : distance * fromIndex - distance * progressPercentage; - [self.navigationScrollView setContentOffset:CGPointMake(xOffset, 0)]; - [self setAlphaToItemAtIndex:fromIndex withOffset:xOffset]; - [self setAlphaToItemAtIndex:toIndex withOffset:xOffset]; - - [_navigationPageControl setCurrentPage:self.currentIndex]; + CGFloat distance = [self getDistanceValue]; + UIAccelerationValue xOffset = fromIndex < toIndex ? distance * fromIndex + distance * progressPercentage : distance * fromIndex - distance * progressPercentage; + [self.navigationScrollView setContentOffset:CGPointMake(xOffset, 0)]; + [self setAlphaWithOffset:xOffset]; + [_navigationPageControl setCurrentPage:self.currentIndex]; } @@ -152,14 +176,14 @@ [self.navigationPageControl setNumberOfPages:[self.navigationItemsViews count]]; [self.navigationPageControl setCurrentPage:self.currentIndex]; CGSize viewSize = [self.navigationPageControl sizeForNumberOfPages:[self.navigationItemsViews count]]; - CGFloat distance = CGRectGetWidth(self.navigationScrollView.frame) / 2; + CGFloat distance = [self getDistanceValue]; CGFloat originX = (distance - viewSize.width/2); [self.navigationPageControl setFrame:(CGRect){originX, 34, viewSize.width, viewSize.height}]; } - (void)addNavigationViewItem:(UIView*)view index:(NSInteger)index { - CGFloat distance = CGRectGetWidth(self.navigationScrollView.frame) / 2; + CGFloat distance = [self getDistanceValue]; CGSize viewSize = [view isKindOfClass:[UILabel class]] ? [self getLabelSize:(UILabel*)view] : view.frame.size; CGFloat originX = (distance - viewSize.width/2) + self.navigationItemsViews.count * distance; view.frame = (CGRect){originX, 8, viewSize.width, viewSize.height}; @@ -169,28 +193,14 @@ [_navigationItemsViews addObject:view]; } --(void)setAlphaToItemAtIndex:(NSInteger)index withOffset:(UIAccelerationValue)xOffset +-(void)setAlphaWithOffset:(UIAccelerationValue)xOffset { - if (index<0 || index>=[self.navigationItemsViews count]) { - return; - } - - CGFloat distance = CGRectGetWidth(self.navigationScrollView.frame) / 2; - CGFloat alpha; - - if(xOffset < distance * index) { - alpha = (xOffset - distance * (index - 1)) / distance; - }else{ - alpha = 1 - ((xOffset - distance * index) / distance); - } - - UILabel *label = (UILabel*)[self.navigationItemsViews objectAtIndex:index]; - [label setAlpha:alpha]; -} - --(CGSize) getLabelSize:(UILabel *)label -{ - return [[label text] sizeWithAttributes:@{NSFontAttributeName:[label font]}];; + CGFloat distance = [self getDistanceValue]; + [self.navigationItemsViews enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { + int index = (int)idx; + CGFloat alpha = xOffset < distance * index ? (xOffset - distance * (index - 1)) / distance : 1 - ((xOffset - distance * index) / distance); + [obj setAlpha:alpha]; + }]; } -(UILabel *)createNewLabelWithText:(NSString *)text @@ -203,9 +213,22 @@ return navTitleLabel; } +-(CGSize)getLabelSize:(UILabel *)label +{ + return [[label text] sizeWithAttributes:@{NSFontAttributeName:[label font]}];; +} + +-(CGFloat)getDistanceValue +{ +// CGPoint middle = [self.navigationController.navigationBar convertPoint:self.navigationController.navigationBar.center toView:self.navigationView]; +// CGFloat width = middle.x - self.navigationView.frame.origin.x; + CGFloat width = CGRectGetWidth(self.navigationView.frame); + return width / 2; +} + -(void)setCurrentNavigationScrollViewOffset { - CGFloat distance = CGRectGetWidth(self.navigationScrollView.frame) / 2; + CGFloat distance = [self getDistanceValue]; UIAccelerationValue xOffset = distance * self.currentIndex; [self.navigationScrollView setContentOffset:CGPointMake(xOffset, 0)]; }