rendering

Break down

An overview of

Page composition: Map view mapVC, resource information view soureVC(view controller’s view has a UITableView). Animation effect: 1. Slide up :soureVC slides up slowly by sliding, and when it reaches the upper limit, it just slides tableView 2. Slide: Slide soureVC down only when the TableView slides to the head.

Analysis of the

  1. First we must add the pan gesture UIPanGestureRecognizer to the sourceVC view
  2. Gesture implementation method according to the Pan gesture of the three states of sourceVC view origin processing
First, a few methods: translationInView: the position (x,y) of the finger moving on the view is positive down and right, and negative up and left. LocationInView: The position of the finger on the view (x,y) is the position of the finger in the view's own coordinate system. VelocityInView: finger moves on to the view of the speed (x, y), plus or minus is also on behalf of the direction, it is worth mentioning in absolute terms | | x > | y | level mobile, | y | > | | x vertical movement. - (void)panGestureRecognized:(UIPanGestureRecognizer *)recognizer{ CGPoint point = [recognizer translationInView:self.view]; // 1. Gesture start: recordsourceThe original origin of the vc. view must be recorded as an attribute to smooth the movement process, otherwise it will be stuckif(recognizer.state == UIGestureRecognizerStateBegan) { self.containerOrigin = recognizer.view.frame.origin; } // 2. In the process of gesture movement: make judgment at the boundary and other positionsif (recognizer.state == UIGestureRecognizerStateChanged) {
        
        CGRect frame = recognizer.view.frame;
        frame.origin.y = self.containerOrigin.y + point.y;
        
        if(frame.origin. Y < 192) {// Upper boundary frame.origin. }if(frame.origin. Y > screen_height-statusandnavigationbar_height-194) {frame.origin STATUSANDNAVIGATIONBAR_HEIGHT - 194; } recognizer.view.frame = frame; } // 3. After the gesture ends: upward trend, view slides directly to the upper boundary; downward trend, view slides directly to the lower boundaryif (recognizer.state == UIGestureRecognizerStateEnded){
                
        if ([recognizer velocityInView:self.view].y < 0) {
            NSLog(@"向上"); [UIView animateWithDuration:0.20 animations:^{CGRect frame = recognizer.viet.frame; frame.origin. Y = 192; UIView animateWithDuration:0.20 animations:^{CGRect frame = recognizer.viet.frame; frame.origin. recognizer.view.frame = frame; } completion:^(BOOL finished) { self.sourceVC.tableView.contentOffset = CGPointMake(0, 0); self.sourceVC.tableView.scrollEnabled = YES; }]; }else {
            NSLog(@"Down"); [UIView animateWithDuration:0.20 animations:^{CGRect frame = recognizer.viet.frame; frame.origin. Y = SCREEN_HEIGHT - STATUSANDNAVIGATIONBAR_HEIGHT - 194; recognizer.view.frame = frame; } completion:^(BOOL finished) { self.sourceVC.tableView.contentOffset = CGPointMake(0, 0); self.sourceVC.tableView.scrollEnabled = NO; }]; }}}Copy the code
  1. Because there is a TableView on our sourceVC, it will cause the tableView sliding gesture conflict with pan sliding gesture, which is why I shield the TableView scrollEnabled in the process of sliding up. But when sourceVC slides to the upper boundary, we unscrew the slider scrollEnabled of the TableView, and there is no problem with the slide up (due to the upper boundary), But there is a problem with sliding. The sliding gesture of TableView conflicts with our custom Pan gesture. Sliding tableView results in sliding the sourceVC view together, which is obviously not consistent with the effect. Therefore, it needs to be handled as follows:
/ / implementation UIGestureRecognizerDelegate agent method, returns YES expressed support for multiple gestures trigger at the same time, Otherwise, multiple gestures cannot be triggered at the same time. - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{if ([otherGestureRecognizer.view isKindOfClass:[UITableView class]]) {
        UITableView *tab = (UITableView *)[otherGestureRecognizer view];
        CGPoint vel = [tab.panGestureRecognizer velocityInView:tab];
        if(vel.y > 0) {// Drop down, CGPoint Point= TAB. ContentOffset is allowed only when contentOffset is 0;return Point.y == 0;
            
        }else{/ /returnNO; }}return NO;
}
Copy the code

The end of the