non*_*uma 6 iphone objective-c ios
我想用这个跟踪索引UIPageViewController.每当我刷卡我需要index++或index--.无论何时向后或向后滑动,都会调用此委托方法:
- (void)pageViewController:(UIPageViewController *)pvc didFinishAnimating:(BOOL)finished previousViewControllers:(NSArray *)previousViewControllers transitionCompleted:(BOOL)completed
{
// If the page did not turn
if (!completed)
{
// You do nothing because whatever page you thought
// the book was on before the gesture started is still the correct page
return;
}
// I want to check here whenever the page was swiped back or further
}
Run Code Online (Sandbox Code Playgroud)
如果用户向后或向后滑动,我该如何检查此方法?我知道有2个DataSource方法"viewControllerAfterViewController"和"viewControllerBeforeViewController",但我无法检查页面转换是否已完成(我可以在上面的方法中执行此操作)任何想法我怎么知道用户是否向后滑动或进一步以上方法?
使用协议:
MyClass : UIViewController <UIPageViewControllerDataSource,UIPageViewControllerDelegate
Run Code Online (Sandbox Code Playgroud)
声明属性:
@property(nonatomic) NSInteger currentIndex;
@property(nonatomic) NSInteger nextIndex;
Run Code Online (Sandbox Code Playgroud)
并在方法中:
-(void)pageViewController:(UIPageViewController *)pageViewController willTransitionToViewControllers:(NSArray *)pendingViewControllers{
NewsTableViewController *controller = [pendingViewControllers firstObject];
self.nextIndex = [self.arrViews indexOfObject:controller];
}
-(void)pageViewController:(UIPageViewController *)pageViewController didFinishAnimating:(BOOL)finished previousViewControllers:(NSArray *)previousViewControllers transitionCompleted:(BOOL)completed{
if (completed) {
self.currentIndex = self.nextIndex;
}
self.nextIndex = 0;
}
Run Code Online (Sandbox Code Playgroud)
那里你将有当前页面.感谢Corey Floyd在这里输入链接描述
根据文档,似乎没有办法判断用户是否向前或向后滑动了页面。布尔值“finished”将告诉您用户是否已完成翻页。
解决方法:
创建一个 int 变量并使用 viewControllerAfterViewController 和 viewControllerBeforeViewController 方法增加或减少该变量的值。用它来测试它们是向前还是向后移动。
presentationIndexForPageViewController 编辑:您可以从文档中使用
编辑2:在此处检查此链接有一种名为setViewControllers:direction:animated:completion:方向的方法将是UIPageViewControllerNavigationDirectionForward或UIPageViewControllerNavigationDirectionReverse
编辑 3:代码 - 假设您知道前进或后退将调用哪个视图控制器:
在您的 appDelegate 上创建一个变量和一个 setter 方法:
int indexVar;
- (void)setIndex:(int)indexVar;
Run Code Online (Sandbox Code Playgroud)
然后在视图控制器上(向前或向后)增加值或减少值(viewDidLoad):
(AppDelegate *)[[UIApplication sharedApplication] delegate] setIndex:<whatever>];
Run Code Online (Sandbox Code Playgroud)
沿着这些思路。这不是实现您目标的确切方法,但希望它能让您朝着正确的方向前进。
| 归档时间: |
|
| 查看次数: |
12055 次 |
| 最近记录: |