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

浏览:36日期:2023-12-19

问题描述

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

问题解答

回答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的逻辑。objective-c - 新手求教网易新闻中效果实现

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

相关文章: