objective-c - 新手求教网易新闻中效果实现
PHPz
PHPz 2017-04-21 11:19:07
0
1
961

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

PHPz
PHPz

学习是最好的投资!

reply all(1)
黄舟

Let me talk about how to implement this on iOS.

Generally, this kind of app uses a navigation controller, uses a tableview to display a list of news titles, and clicks to display the news text.

Your question is how to implement left and right swiping, such as in the view of the news text
Add

in 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];

Then you can define the implementation of left and right sliding (implemented with segue in iOS)

    - (void)rightSwipeHandle:(UISwipeGestureRecognizer*)gestureRecognizer
{
    [self.navigationController popViewControllerAnimated:YES];
}

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

This is a thumbnail of the storyboard, you can clearly see the logic of the entire app.

I wrote out the prototype by the way. The source code is here. Please look at the source code carefully. I hope it will be helpful to you.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template