根据与scrollsToTop
相关的官方UIScrollView文档:
If that scroll view has scrollsToTop set to NO, its delegate returns NO from scrollViewShouldScrollToTop:, or the content is already at the top, nothing happens.
因此,当我点击状态栏时 ScrollView 位于顶部时,委托(delegate)方法 scrollViewShouldScrollToTop:
不会被触发。但是,我正在尝试利用此调用以编程方式自行决定层次结构中的哪个 ScrollView 需要滚动。
那么最好的替代方法是什么?我正在尝试找到一种方法来捕捉状态栏上的点击。根据我所读到的内容,这听起来像是接听电话并适当处理电话的最佳方式。
编辑:我能想到的下一个最佳替代方案是通过位于顶部的不同 UIWindow 在状态栏顶部放置一个带有 UITapGestureRecognizer 的清晰 UIView。
最佳答案
因为 iOS7 Controller View 默认位于 statusBar 和 navigationBars 之下。
您可以利用这一点,将 TapGestureRecognizer 添加到 VC 的主视图中。在 tap delegate 方法中检查 View 中被点击的点是否属于状态栏框架。
- (void)userTappedOnView:(UITapGestureRecognizer *)recognizer {
if (recognizer.state == UIGestureRecognizerStateEnded) {
CGPoint tapLocation = [recognizer locationInView:self.view];
CGRect statusBarFrame = [[UIApplication sharedApplication] statusBarFrame];
if (CGRectContainsPoint(statusBarFrame, point)) {
//Scroll other views to top here..
}
}
}
关于ios - UIScrollView scrollViewShouldScrollToTop : alternative available when already at the top?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22358682/