简体   繁体   English

UIScrollView-如何摆脱滚动之前的延迟?

[英]UIScrollView - how to get rid of delay before scrolling?

I'm using a UIScrollView to display a custom UIView . 我正在使用UIScrollView显示自定义UIView When the user drags a finger across the UIScrollView , there is a noticeable delay before the display begins updating. 当用户在UIScrollView drags手指时,显示开始更新之前会有明显的延迟。 If the user keeps touching the screen, the UIScrollView becomes very responsive after a short time. 如果用户不断touching屏幕,则UIScrollView会在短时间内变得非常敏感。 Subsequent attempts to scroll result in the same initial delay, followed by high responsiveness. 随后的scroll尝试会导致相同的初始延迟,然后响应速度很快。 This delay seriously affects the usability of the view and I would like to get rid of it. 这种延迟严重影响了视图的可用性,我想摆脱它。

In a test project I have written to try to get to the bottom of this issue, I have only been able to partially replicate the behaviour. 在我写的一个测试项目中,试图深入探究这个问题,我只能部分复制行为。 The first time that the user scrolls is exactly the same - however any subsequent attempts to scroll are responsive straight away. 用户的第一次scrolls是完全相同的-但是随后进行的任何scroll尝试都会立即做出响应。

I have tried both setting delaysContentTouches = NO and subclassing UIScrollView so that touchesShouldBegin returns NO as suggested in multiple places online, but neither has worked. 我尝试过设置delaysContentTouches = NO和子类化UIScrollView以便touchesShouldBegin returns NO在网上多个地方都建议touchesShouldBegin returns NO ,但是都没有起作用。

I'm using MonoTouch on iOS 4.3 , but Objective-C answers are fine. 我在iOS 4.3上使用MonoTouch ,但是Objective-C答案很好。 I would post code to help illustrate the issue, but since I have been unable to narrow down the problem this would be well over 1000 lines. 我将发布代码来帮助说明问题,但是由于我无法缩小问题的范围,因此可能超过1000行。 Hopefully this is enough info to get a solution. 希望这是足够的信息以获得解决方案。

Does anyone know what might be causing this delay, and how I can get rid of it? 有谁知道可能导致这种延迟的原因,以及如何消除这种延迟?

Some general suggestions for improving scrolling performance. 有关改善滚动性能的一些一般建议。

Have your scrolling views rasterize offscreen: 让滚动视图在屏幕外光栅化:

myView.layer.shouldRasterize = YES;

Set that property for each sub-view on the scrollview - do not set it for the children of those sub-views or you just eat up memory that way. 为滚动视图上的每个子视图设置该属性-不要为那些子视图的子视图设置该属性,否则您将以这种方式消耗内存。

If your scrolling views do not need compositing, make sure you turn that blending off: 如果滚动视图不需要合成,请确保关闭该混合:

myView.opaque = YES;

Test using the simulator by leveraging these two features that appear on the Debug menu of the iOS Simulator: 通过利用iOS模拟器的“调试”菜单上显示的以下两个功能,使用模拟器进行测试:

  • Color Off-screen Rendered 彩色屏外渲染
  • Color Blended Layers 颜色混合层

If that doesn't address your problem, and you have implemented UIScrollViewDelegate, double-check to make sure you are not doing anything time consuming in those methods - for example, based on your description, you might be doing something in scrollViewDidScroll , scrollViewWillBeginDragging , or scrollViewWillBeginZooming and if you are, optimize that so it happens before scrolling even begins. 如果那不能解决您的问题,并且您已经实现了UIScrollViewDelegate,请仔细检查以确保您在这些方法中没有花费任何时间-例如,根据您的描述,您可能在scrollViewDidScrollscrollViewWillBeginDragging中进行了操作或scrollViewWillBeginZooming ,然后进行优化,以使其发生在滚动甚至开始之前。 Also, make sure you're not doing anything in touchesBegan . 另外,请确保您没有做任何事情touchesBegan

I suspect what is happening is there is some kind of interaction enabled in the content of your scroll view. 我怀疑正在发生的事情是您的滚动视图的内容中启用了某种交互。

The system does not know if the initial touch down is going to be a tap on one of the subviews or a drag on the scroll view, therefore is causing a delay while it waits to see if you are going to lift your finger. 系统不知道初始触摸是在子视图之一上单击还是在滚动视图上拖动,因此在等待您是否抬起手指时会造成延迟。

What are the subviews of the UIScroll view? UIScroll视图的子视图是什么?

As an experiment set all the subviews of the UIScrollView to have userInteractionEnabled = NO , this will not be what you want, but its just a test. 作为实验,将UIScrollView的所有子视图设置为userInteractionEnabled = NO ,这不是您想要的,而只是一个测试。 Is should scroll fine after this, otherwise I am wrong. 此后应该滚动良好,否则我错了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM