很抱歉这个标题很长而且不言自明,但是 UIScrollView 提出了很多问题,我发现很难找到在不同情况下可能有帮助的问题。
我的 iPad 应用程序中有嵌套的 ScrollView 。到目前为止一切顺利,一切都有起伏,但它非常灵活且 react 灵敏。我的外部 ScrollView 是分页 View ,其中包含全屏或更大的内容 ScrollView 。外部 ScrollView 是水平的,内部是垂直的。就像照片库之一。我发现当我缩放和滚动内部 ScrollView 时,检测慢速和长滑动手势时有明显的延迟仅当 ScrollView 向下滚动到内容底部并且弹跳关闭时。
另一件事是内部 ScrollView 弹跳属性伪随机地变为是/否。所以,这是构造函数中的代码,它设置了起作用的内部 ScrollView :
if (UIInterfaceOrientationIsPortrait(forOrientation)) {
self.minimumZoomScale = 1.0;
self.maximumZoomScale = 1.0;
self.bounces = NO;
self.alwaysBounceVertical = NO;
self.scrollEnabled = NO;
}else if (UIInterfaceOrientationIsLandscape(forOrientation)){
self.minimumZoomScale = 1.333333f;
self.maximumZoomScale = 1.333333f;
self.bounces = YES;
self.alwaysBounceVertical = YES;
self.scrollEnabled = YES;
}
self.scrollsToTop = NO;
self.showsVerticalScrollIndicator = YES;
self.showsHorizontalScrollIndicator = NO;
self.directionalLockEnabled = YES;
self.delegate = self;
self.pagingEnabled = NO;
self.canCancelContentTouches = NO;
self.delaysContentTouches = YES;
当 iPad 旋转时, ScrollView 也会出现弹跳,并且也会出现弹跳故障。
这是一个错误吗?还是我把事情搞砸了?
提前感谢您的时间和兴趣!
更新: 我嵌套了两个 ScrollView ,它们实际上是 UIScrollView 的子类。我这样做是因为我还需要重写 hitTest 其他方法。我还尝试了这里描述的更好的解决方案 http://openradar.appspot.com/8045239并没有得到任何好的结果。
最佳答案
我正在回答我自己的问题。
Open radar's bug solution that posted on the question post,它不是很清楚要隔离什么以阻止 uiscrollview 调整大小和取消弹跳
基本上,在 layoutSubViews 期间可以更改 View 框架的所有事情都必须只执行一次,方法是仔细检查大小是否等于 layoutSubviews 中编码的更改,然后不会运行超过一次。
-(void)layoutSubviews {
///...
if (!self.bounces) {
self.bounces = YES;
}
if(!self.scrollEnabled){
self.scrollEnabled = YES;
}
if (!CGSizeEqualToSize(rect.size, self.contentSize)) {
self.contentSize = rect.size;
}
if (self.zoomScale < MAXIMUM_ZOOM_SCALE ) {
[self zoomToRect:ZOOM_RECT_MAKE animated:NO];// otherwise this line of code won't do anything at all
}
}
关于ios - 当弹跳设置为 NO 时,嵌套的 UIScrollView 不会弹跳并且不会检测慢速滑动手势,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5225178/