Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/114.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UIPageControl当前页面指示器在显示新视图之前切换_Ios_Objective C_Iphone_Uipageviewcontroller_Uipagecontrol - Fatal编程技术网

Ios UIPageControl当前页面指示器在显示新视图之前切换

Ios UIPageControl当前页面指示器在显示新视图之前切换,ios,objective-c,iphone,uipageviewcontroller,uipagecontrol,Ios,Objective C,Iphone,Uipageviewcontroller,Uipagecontrol,我用PageControl实现了一个漂亮的UIPageViewControl。滑动时,指示灯会改变并显示正确的当前页面 然而,我注意到当前页面指示器切换所需要的只是开始滑动。这意味着,如果我开始刷卡,然后放开手指,当前页面指示器已经切换,就像页面已经切换一样,但它没有。这是我用来切换的代码: - (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIVi

我用
PageControl
实现了一个漂亮的
UIPageViewControl
。滑动时,指示灯会改变并显示正确的当前页面

然而,我注意到当前页面指示器切换所需要的只是开始滑动。这意味着,如果我开始刷卡,然后放开手指,当前页面指示器已经切换,就像页面已经切换一样,但它没有。这是我用来切换的代码:

- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated{

    NSUInteger index = [self.navigationController.viewControllers indexOfObject:viewController];
    self.pageControl.currentPage = index;
}
我注意到的另一件事是,当我快速左右滑动更改视图时,页面指示器卡住了,无法移动

因此,它只在您不快速更改视图的情况下起作用。如果你需要任何额外的代码,请告诉我。多谢各位

编辑

这是我用来实现UIPageViewController的代码

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Create the data model

    self.navigationItem.title = @"Tabell";
    self.identifiers = [[NSMutableArray alloc] init];

    [self.identifiers addObject:@"rankTable"];
    [self.identifiers addObject:@"page2"];

    // Create page view controller
    self.pageViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"PageViewController"];
    self.pageViewController.dataSource = self;
    self.pageViewController.delegate = self;


    self.navigationController.delegate = self;
    CGSize navBarSize = self.navigationController.navigationBar.bounds.size;
    CGPoint origin = CGPointMake( navBarSize.width/2, navBarSize.height/2 );
    self.pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(origin.x, origin.y+16,
                                                                       0, 0)]; //Here added 45 to Y and it did the trick


    self.pageControl.pageIndicatorTintColor = navbarColor;
    self.pageControl.currentPageIndicatorTintColor = [UIColor lightGrayColor];

    [self.pageControl setNumberOfPages:2];

    [self.navigationController.navigationBar addSubview:self.pageControl];

    UITableViewController *startingViewController = [self viewControllerAtIndex:0];
    NSArray *viewControllers = @[startingViewController];
    [self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];

     CGFloat tabBarHeight = self.tabBarController.tabBar.frame.size.height;

    // Change the size of page view controller
    self.pageViewController.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - tabBarHeight);

    [self addChildViewController:_pageViewController];
    [self.view addSubview:_pageViewController.view];
    [self.pageViewController didMoveToParentViewController:self];

}

为什么不实现
UIPageViewControllerDelegate


-pageViewController:didFinishAnimating:PreviousViewController:transitionCompleted:
方法?它有一个
transitionCompleted
布尔值,告诉您是否应该更新页面控件。您当前的实现似乎有问题,因为一旦您开始浏览页面,它就会为下一页加载一个视图控制器,并调用
…didShow…
方法。希望这个hepls。

快速更改视图时,它根本不移动,或者在移动完成后移动?它根本不移动@Sasquatchn不是一个复制品,但您可以使用类似的技术:我不知道它是如何实现的。宽度的值是多少@piccianoIt是页面宽度,通常与滚动视图宽度相同。我试图实现这一点。我在函数中放了一个NSLog,它和我当前的函数一样工作。我一开始刷卡NSLog就启动了?你检查过“transitionCompleted”布尔值吗?