IOS development – imitation micro-blog home page effect

In imitation of the micro-blog home page, do the small changes, the effect how, to see all the needs of the project:
subsection controller uses YUSegment;
amplification using HFStretchableTableHeaderView head down, although this for a long time, but it is very practical; because
is demo, so the use of the built-in UIPageViewController, for some defects of this control, you do not spray, can be replaced according to their own needs; a method of
is more important in my demo:

Just allow the simultaneous identification of multiple gestures - (BOOL) gestureRecognizer: (UIGestureRecognizer * gestureRecognizer) shouldRecognizeSimultaneouslyWithGestureRecognizer: (UIGestureRecognizer * otherGestureRecognizer) {return YES;}

The main controller I use is UItableView, put three sub controllers in a cell TableView, to achieve, there are many ways to achieve this effect, this one, three sub controllers are inherited in a BaseTableViewController, is mainly used to judge whether the controller can easily slide:

- (void) scrollViewDidScroll: (UIScrollView * scrollView) {/ / drop amplification must implement the [_stretchableTableHeaderView scrollViewDidScroll:scrollView]; / / UIImage *image calculation of navigation transparency [UIImage imageNamed:@ = "pc_bg"]; CGFloat minAlphaOffset = 0; CGFloat = maxAlphaOffset image.size.height-64; CGFloat offset = scrollView.contentOffset.y; CGFloat = alpha (offset - minAlphaOffset) / (maxAlphaOffset - minAlphaOffset); _barImageView.alpha = Alpha; / / according to the navigation bar (alpha > if title opacity; 0.5) {self.title = @ "name";} else {self.title = "@";} / / sub controller and main controller between the sliding state switch CGFloat tabOffsetY = [_tableView rectForSection:0 ].origin.y-64; if (scrollView.contentOffset.y = > tabOffsetY) {scrollView.contentOffset = CGPointMake (0, tabOffsetY); if (_canScroll) {/ / notify sub controller can slide, in fact, this notice is able to avoid the [[NSNotificationCenter defaultCenter] postNotificationName:@ "kScrollToTopNtf" object:@1]; _canScroll = NO; / / told the sub controller in cell can slide self.contentCell.canScroll = YES;}} else {if (! _canScroll) {scrollView.contentOffset = CGPointMake (0, tabOffsetY);}}}

In addition to solve the sliding around pageView, will drive the main controller sliding up and down, my principle is to monitor the pageView gesture:

///pageView - (void) customPageView NSDictionary [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:UIPageViewControllerSpineLocationMin] {*option = forKey:UIPageViewControllerOptionSpineLocationKey]; self.pageViewCtrl = "UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:option]; self.pageViewCtrl.dataSource = self; self.pageViewCtrl.delegate = self; PersonalLeftViewController = *ctrl1 [[PersonalLeftViewController alloc] init]; PersonalMiddleViewController *ctrl2 = [[PersonalMiddleViewController alloc] init] PersonalRightViewController; *ctrl3 [[PersonalRightViewController alloc] = init]; self.dataArray = @[ctrl1, ctrl2, ctrl3].mutableCopy; [self.pageViewCtrl setViewControllers:@[self.dataArray[0]] direction: UIPageViewControllerNavigationDirectionForward animated:YES completion:nil]; [self.contentView addSubview:self.pageViewCtrl.view]; for (UIView *view in self.pageViewCtrl.view.subviews) if ([view isKindOfClass:[UIScrollView class]]) {{/ / listen drag gesture "panGestureRecognizer.state" options [view addObserver:self forKeyPath:@ NSKeyValueObservingOptionNew context:nil];}} [self.pageViewCtrl.view mas_makeConstraints:^ (MASConstraintMaker* make) {make.edges.equalTo (self.contentView);}];}
Listen / drag gesture correction (void) - observeValueForKeyPath: (NSString *) keyPath ofObject: (ID) object change: (NSDictionary< NSKeyValueChangeKey, id> change (void * *) context: (context) {if ((UIScrollView) object).PanGestureRecognizer.state = = UIGestureRecognizerStateChanged) {NSLog (@ bottomSView slide, so that the main controller not allowed to slide "); [[NSNotificationCenter defaultCenter] postNotificationName:@" PageViewGestureState "object:@" changed "];} else (if ((UIScrollView) object).PanGestureRecognizer.state = = UIGestureRecognizerStateEnded) {NSLog (@" end of drag "); [[NSNotificationCenter defaultCenter] postNotificationName:@ PageVi" EwGestureState "object:@" ended ";}}

Important part of so much, in fact, very simple, but I’m not a long time to write a blog, write a bit messy, or pick up the code demo:
demo:https://github.com/hkjin/PersonalHomePageDemo

Design sketch

IOS development - imitation micro-blog home page effect
Untitled.gif