English 中文(简体)
UIPageControl 显示页数不正确
原标题:UIPageControl showing incorrect page

I ve got a UIScrollView including several table, and a UIPageControlding Line of which page theuser is present viewing. 它进行精彩的UNTIL,即开始在表格上浏览,届时UIPageControl调整,并(正确)说,我们正处于第一页。

我的守则是:

- (void)scrollViewDidScroll:(UIScrollView *)_scrollView {
  if (pageControlIsChangingPage) {
    return;
  }

  /*
   *  We switch page at 50% across
   */
  CGFloat pageWidth = _scrollView.frame.size.width;
  int page = floor((_scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
  pageControl.currentPage = page;
}

而且:

- (void)scrollViewDidEndDecelerating:(UIScrollView *)_scrollView {
  pageControlIsChangingPage = NO;
}

不知道究竟是什么原因造成这种情况? 倾斜:

最佳回答

我认为,问题是,由于两位代表都自行决定,《可上诉意见》和《可上诉意见》都采用了相同的滚动方法。 我在主要滚动表上增加了一个标签,然后在调整该页时对塔格进行检查。

if (_scrollView.tag == 100) {

CGFloat pageWidth = _scrollView.frame.size.width;
int page = floor((_scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
pageControl.currentPage = page;

}

最后

问题回答

当你上页时,这页是否正确?

if (pageControlIsChangingPage)
  return;

似乎在您不改动页(即,你将表象照发),<代码>return<>。 未执行。 ......

CGFloat pageWidth = _scrollView.frame.size.width;
int page = floor((_scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
pageControl.currentPage = page;

部分内容将在此刻执行,_scrollView.contentOffset.x将小于pageWidth / 2(其中7项可改为0),因为你只是滚动/下,因此,page >。





相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签