我有一个UIPageViewController在滚动时具有垂直方向,但在按下状态栏时它不会滚动到顶部。如果有帮助,页面上没有其他滚动视图。
是否有页面视图控制器的scrolltotop功能?
答案 0 :(得分:0)
// AppDelegate.m
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesBegan:touches withEvent:event];
[[NSNotificationCenter defaultCenter] postNotificationName:@"touchStatusBarClick" object:nil];
}
// ViewController.m
- (void)viewDidLoad
{
// add this line at the bottom of the function
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(statusBarTouched) name:@"touchStatusBarClick" object:nil];
}
// This function is called when status bar is touched
-(void) statusBarTouched
{
PageContentViewController *startingViewController = [self viewControllerAtIndex:0];
NSArray *viewControllers = @[startingViewController];
[self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionReverse animated:YES completion:nil];
}
我希望它有所帮助。
答案 1 :(得分:0)
为了便于实施,您可以在childVC中使用此代码。此设置将仅使可见的ChildVC成为scrollsToTop-able。
- (void)viewDidLoad
{
self.collectionView.scrollsToTop =NO;
}
-(void)viewDidAppear:(BOOL)animated
{ self.collectionView.scrollsToTop =YES;
}
-(void)viewWillDisappear:(BOOL)animated
{
self.collectionView.scrollsToTop =NO;
}