【问题标题】:Pagecontrol dots are not changing页面控制点没有改变
【发布时间】:2013-03-26 11:28:44
【问题描述】:

我正在尝试使用page control。这就是我所做的。我在storyboard 的视图中添加了一个。

然后在我的ViewDidLoad

   images = [[NSMutableArray alloc]initWithObjects:[UIImage imageNamed:@"img1.jpg"],[UIImage imageNamed:@"img2.jpg"],[UIImage imageNamed:@"img3.jpg"],[UIImage imageNamed:@"img4.jpg"], nil];
    pagecontrol = [[UIPageControl alloc]init];
    self.imageIndex = 0;
    [pagecontrol setNumberOfPages:images.count];
    [pagecontrol setCurrentPage:imageIndex]; 

如您所见,我有一个包含四个图像的数组。我在图像视图上添加了一个页面控件。我还在 imageView 上添加了两个滑动手势(左右)。我现在想做的是,当我刷卡时:

  • 图像已更改
  • 点已更新为数组中的正确位置

这是我的右滑代码:

- (void)next:(UITapGestureRecognizer *)recognizer {
    if(imageIndex == images.count-1){
        imageIndex = images.count-1;
    }else{
        imageIndex++;
    }
    [UIView transitionWithView:self.imgGallery
                      duration:1.0f
                       options:UIViewAnimationOptionTransitionCrossDissolve
                    animations:^{
                        self.imgGallery.image = [images objectAtIndex:imageIndex];

                    } completion:nil];
    [pagecontrol setCurrentPage:imageIndex];
}

问题

我的图像正在正确更改。但是我的 pagecontrol 点没有更新,而且它只显示 3 个点。

有人可以帮忙吗?

【问题讨论】:

  • 将当前页面值设置为 3 或 4(0 除外)并检查加载页面控件,点是否放置正确@Stef Geelen

标签: iphone ios objective-c uipagecontrol


【解决方案1】:
  1. 在滚动视图中启用分页

[self.scrollView setPagingEnabled:YES];

  1. 将委托设置为您的滚动视图

【讨论】:

  • 我没有滚动视图?它应该始终与滚动视图结合使用吗?
【解决方案2】:

你在哪里定义了一个 pageControll

 [_tutorialPageControll addTarget:self action:@selector(changPage) forControlEvents:UIControlEventValueChanged];
_tutorialPageControll.currentPage = 0;
    _tutorialPageControll.numberOfPages = TutorialArray.count;

以及您想要更改页面的位置

_tutorialPageControll.currentPage = imageIndex;

【讨论】:

    猜你喜欢
    • 2023-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-19
    相关资源
    最近更新 更多