搜尋

首頁  >  問答  >  主體

objective-c - 新手求教網易新聞中效果實現

在網易新聞客戶端中,具體一篇新聞裏,用手勢右滑,返回列表,左滑出現評論頁,頂部的 navigation也能跟著一起動,這種效果怎麼實現的,有具體實例更好,求教

PHPzPHPz2806 天前983

全部回覆(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
  • 取消回覆