UIPageViewController的进展 [英] Progress of UIPageViewController

查看:124
本文介绍了UIPageViewController的进展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在页面滚动过程中从uipageviewcontroller接收更新。我想知道%的transitionProgress。 (当用户移动手指以进入另一页时,此值应更新)。我对从一个页面到另一个页面的动画进度感兴趣,而不是对总页数的进展感兴趣。

I would like to receive updates from the uipageviewcontroller during the page scrolling process. I want to know the transitionProgress in %. (This value should update when the user move the finger in order to get to another page). I'm interested in the animation progress from one page to another, not the progress through the total number of pages.

到目前为止我发现的内容:

What I have found so far:


  • 有一个名为 UICollectionViewTransitionLayout ,其属性对应于我要查找的内容,transitionProgress。可能uipageviewcontroller会以某种方式实现这个方法吗?

  • There is a class called UICollectionViewTransitionLayout that have the property corresponding to what I am looking for, "transitionProgress". Probably uipageviewcontroller implement this method somehow?

我可以在uipagecontroller上调用以下方法,但结果只得到0!

I can call the following method on the uipagecontroller but I only get 0 as result!

CGFloat percentComplete = [self.pageViewController.transitionCoordinator percentComplete];

CGFloat percentComplete = [self.pageViewController.transitionCoordinator percentComplete];

推荐答案

最后我发现了一个解决方案,即使它可能不是最好的方法:

At last I found out a solution, even if it is probably not the best way to do it:

我首先在scrollview上添加一个观察者,如下所示:

I first add an observer on the scrollview like this:

// Get Notified at update of scrollview progress
NSArray *views = self.pageViewController.view.subviews;
UIScrollView* sW = [views objectAtIndex:0];
[sW addObserver:self forKeyPath:@"contentOffset" options:NSKeyValueObservingOptionNew context:NULL];

当观察者被召唤时:

NSArray *views = self.pageViewController.view.subviews;
UIScrollView* sW = [views objectAtIndex:0];
CGPoint point = sW.contentOffset;

float percentComplete;
//iPhone 5
if([ [ UIScreen mainScreen ] bounds ].size.height == 568){
    percentComplete = fabs(point.x - 568)/568;

} else{
//iphone 4
    percentComplete = fabs(point.x - 480)/480;
}
NSLog(@"percentComplete: %f", percentComplete);

我很高兴我发现了这个: - )

I'm very happy that I found this :-)

这篇关于UIPageViewController的进展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆