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

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

PHPz
PHPz

学习是最好的投资!

Antworte allen(1)
黄舟

我来说一下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的逻辑。

我顺便把原型写出来了,源代码在这里,你仔细的看一下源代码,希望对你有所帮助。

Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage