【发布时间】:2015-05-19 11:12:14
【问题描述】:
我已经实现了一个 niceUIPageViewControl 和一个PageControl。当滑动指示器改变并显示正确的当前页面。
但是我注意到当前页面指示器切换所需的只是开始滑动。这意味着如果我开始滑动然后松开手指,当前页面指示器已经切换,就像页面已经切换但它没有切换一样。这是我用来进行切换的代码:
- (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];
}
【问题讨论】:
-
快速换视图时,完全不动还是动完后才动?
-
它根本不动。 @sasquatch
-
不是重复的,但您可以使用类似的技术:stackoverflow.com/questions/6310031/…
-
我不明白它是如何实现的。价值的宽度是多少? @picciano
-
它是页面宽度,通常与滚动视图宽度相同。
标签: ios objective-c iphone uipageviewcontroller uipagecontrol