当前位置: 代码迷 >> 综合 >> 上拉跳转界面,仿淘宝
  详细解决方案

上拉跳转界面,仿淘宝

热度:51   发布时间:2023-09-21 02:28:16.0

项目中提出这么个需求,在首页中上拉,然后直接跳转到地图找房界面,想了下,用监听scrollview加动画实现了这一效果,上代码:


// 监听scrollview的滑动事件,这里我设置了上拉距离超过200就跳转

-(void)scrollViewDidScroll:(UIScrollView *)scrollView {

    

    NSLog(@"%f",scrollView.contentOffset.y);

    

    if (scrollView.contentOffset.y >= 200) {

        [self pushToMapSearchHouseVC];

    }

    

}


// 跳转

-(void)pushToMapSearchHouseVC {


    // 搞一个动画

    CATransition *trans = [CATransition animation];

    trans.duration = 1;

    trans.type = kCATransitionPush;

    trans.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];

    // 设置样式为从底部向上推出

    trans.subtype = kCATransitionFromTop;

    [self.navigationController.view.layer addAnimation:trans forKey:nil];

    MapSerachViewController *VC=[[MapSerachViewController alloc]init];

    VC.type = 3;

    [self.navigationController pushViewController:VC animated:YES];

}


至此,大功告成,若你的ViewController不是滑动视图,要想实现这个效果,可以用 


-(void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{

    

    UITouch *touch = [touches anyObject];

    CGPoint point = [touch locationInView:self.view];

    if (point.y < -200) {

        /*

        跳转

         */

    }

    

}


尝试一下




  相关解决方案