搜尋

首頁  >  問答  >  主體

objective-c - 新手求教网易新闻中效果实现

在网易新闻客户端中,具体一篇新闻里,用手势右滑,返回列表,左滑出现评论页,顶部的 navigation也能跟着一起动,这种效果怎么实现的,有具体实例更好,求教

PHPzPHPz2768 天前958

全部回覆(1)我來回復

  • 黄舟

    黄舟2017-04-21 11:21:07

    我來說一下iOS下這個的實作方法吧。

    一般情況下這種app用的是navigation controller, 用tableview 顯示新聞標題list, 點進去後顯示新聞正文。

    你的問題是左右滑如何實現的,比如在新聞正文的view 裡面
    在viewDidLoad裡面加

    //........towards right Gesture recogniser for swiping.....//
        UISwipeGestureRecognizer *rightRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(rightSwipeHandle:)];
        rightRecognizer.direction = UISwipeGestureRecognizerDirectionRight;
        [rightRecognizer setNumberOfTouchesRequired:1];
        [self.view addGestureRecognizer:rightRecognizer];
        //[rightRecognizer release];
    
        //........towards left Gesture recogniser for swiping.....//
        UISwipeGestureRecognizer *leftRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(leftSwipeHandle:)];
        leftRecognizer.direction = UISwipeGestureRecognizerDirectionLeft;
        [leftRecognizer setNumberOfTouchesRequired:1];
        [self.view addGestureRecognizer:leftRecognizer];
        //[leftRecognizer release];
        [self.navigationController setNavigationBarHidden:YES animated:YES];
    

    接著再定義左右滑的實作就可以(iOS裡用segue實作)

        - (void)rightSwipeHandle:(UISwipeGestureRecognizer*)gestureRecognizer
    {
        [self.navigationController popViewControllerAnimated:YES];
    }
    
    - (void)leftSwipeHandle:(UISwipeGestureRecognizer*)gestureRecognizer
    {
        [self performSegueWithIdentifier:@"forward" sender:self];
    }
    

    這是storyboard的縮圖,可以很清晰的看到整個app的邏輯。

    我順便把原型寫出來了,源代碼在這裡,你仔細的看一下源代碼,希望對你有所幫助。

    回覆
    0
  • 取消回覆