Skip to content

Commit

Permalink
Merge pull request #5 from tarop/feature/fix-view-flickering
Browse files Browse the repository at this point in the history
tabsView がチラつかないようにした
  • Loading branch information
nakajijapan committed May 21, 2015
2 parents 38626db + 7f67610 commit fc45f0e
Showing 1 changed file with 2 additions and 34 deletions.
36 changes: 2 additions & 34 deletions Classes/NKJPagerViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ @interface NKJPagerViewController () <UIPageViewControllerDataSource, UIPageView
@property (nonatomic) NSInteger activeContentIndex;
@property (nonatomic) NSInteger activeTabIndex;

@property (getter=isAnimatingToTab, assign) BOOL animatingToTab;
@property CGPoint movingOffset;

@end

@implementation NKJPagerViewController
Expand Down Expand Up @@ -64,7 +61,6 @@ - (void)defaultSettings
self.heightOfTabView = 44.0;
self.yPositionOfTabView = 64.0;
self.tabsViewBackgroundColor = kTabsViewBackgroundColor;
self.animatingToTab = NO;
}

- (void)defaultSetUp
Expand Down Expand Up @@ -202,8 +198,6 @@ - (void)handleTapGesture:(UITapGestureRecognizer *)sender
}
- (void)trasitionTabViewWithView:(UIView *)view
{
self.animatingToTab = YES;

CGFloat buttonSize = [self.dataSource widthOfTabView];
CGFloat sizeSpace = ([[UIScreen mainScreen] bounds].size.width - buttonSize) / 2;

Expand All @@ -213,7 +207,6 @@ - (void)trasitionTabViewWithView:(UIView *)view
if ([self.delegate respondsToSelector:@selector(viewPager:didSwitchAtIndex:withTabs:)]) {
[self.delegate viewPager:self didSwitchAtIndex:self.activeContentIndex withTabs:self.tabs];
}
self.animatingToTab = NO;
}];
}

Expand Down Expand Up @@ -281,36 +274,11 @@ - (void)pageViewController:(UIPageViewController *)pageViewController

#pragma mark - UIScrollViewDelegate

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
self.movingOffset = scrollView.contentOffset;
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
NSInteger buttonSize = [self.dataSource widthOfTabView];

if (scrollView.tag == 0) { // To move menutab
CGPoint contentOffset = self.tabsView.contentOffset;
CGFloat offset = (scrollView.contentOffset.x - self.movingOffset.x) * (buttonSize / CGRectGetWidth(self.view.frame));

// NSLog(@"offset(%f) self.movingOffset(%@) scrolloffset(%@)", offset, NSStringFromCGPoint(self.movingOffset), NSStringFromCGPoint(scrollView.contentOffset));

if (self.isAnimatingToTab) {
return;
}

// Because the coordinates become negative...
if (scrollView.contentOffset.y < 0) {
self.movingOffset = scrollView.contentOffset;
return;
}

contentOffset.x += offset;
self.tabsView.contentOffset = contentOffset;
self.movingOffset = scrollView.contentOffset;
} else if (scrollView.tag == kTabViewTag) { // To scroll
if (scrollView.tag == kTabViewTag) { // To scroll

NSInteger buttonSize = [self.dataSource widthOfTabView];
CGFloat position = self.tabsView.contentOffset.x / buttonSize;
CGFloat delta = position - (CGFloat)self.leftTabIndex;

Expand Down

0 comments on commit fc45f0e

Please sign in to comment.