这是我的第一篇文章,因为我通常会找到堆栈溢出的所有答案,但这次不是!
我有一个小问题。
我正在使用以下方法:
-(void)scrollToTop;
{
[_scrollView setContentOffset:CGPointZero animated:YES];
}
有时它动画有时没有!
这个有效:
-(void)newPage:(NSString*)href
{
if(!(_pageNumber == href.integerValue))
{
__weak id weakSelf = self;
[(PageViewController*)_preLoadPages[href] setPageMinHeight:_actualPage.height];
NSMutableArray *viewControllers = [[NSMutableArray alloc] init];
viewControllers[0] = _preLoadPages[href];
[self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:^(BOOL finished){
[weakSelf afterLinkClicked:href];
}];
_pageNumber = href.integerValue;
}
}
- (void)afterLinkClicked:(NSString*)href
{
_pageNumber = href.integerValue;
[_preLoadPages[href] setPageMinHeight:0];
_actualPage = _preLoadPages[href];
[_preLoadPages removeAllObjects];
[self updateScrollView];
[self scrollToTop];
[self parsePage];
}
而这个没有:
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
CGPoint test = [gestureRecognizer locationInView:gestureRecognizer.view];
if(test.x>=742)
{
if(_preLoadPages[@"next"]!=nil)
{
__weak id weakSelf = self;
[(PageViewController*)_preLoadPages[@"next"] setPageMinHeight:_actualPage.height];
NSMutableArray *viewControllers = [[NSMutableArray alloc] init];
viewControllers[0] = _preLoadPages[@"next"];
[self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:^(BOOL finished){
[weakSelf afterAnimationCompleted];
}];
}
}
return YES;
}
- (void)afterAnimationCompleted
{
_pageNumber++;
[_preLoadPages[@"next"] setPageMinHeight:0];
_actualPage = _preLoadPages[@"next"];
[_preLoadPages removeAllObjects];
[self updateScrollView];
[self scrollToTop];
[self parsePage];
}
这两个电话之间几乎没有区别!我曾尝试使用 performSelector: withObject: withDelay:0 但它也不起作用!