ios - -(无效)scrollViewDidScroll :(UIScrollView *)scrollView too slow in iOS 8

标签 ios objective-c iphone uiscrollview

我有一个问题,在辅助 scrollview 上向上/向下滚动并从 scrollviewdidscroll 中设置 contentoffset 会导致轻微的抖动行为......或更准确地说是低帧速率。

我目前依靠 scrollViewDidScroll 来管理我的 UIScrollView 中的视差等效果,这些效果是通过监听 scrollViewDidScroll 来应用的,但是每次调用此方法的周转时间(出于某种原因)太慢并且导致足够的延迟以致于滚动时看起来有点糟糕。

有趣的是,iOS 9 运行良好。

我已经尝试过替代方法,例如关闭图像或使用 AsyncDisplayKit,但这两种方法都对触发 scrollViewDidScroll 的次数没有影响。

在我看来,我可能需要重新设计我创建视差效果的方式,但我犹豫是否有快速修复的方法。

最佳答案

首先 - 使用 Xcode Instruments 调试工具“Time Profiler”(Xcode 菜单 Product->Profile,然后从 instruments 中选择 Time Profiler)。

不要忘记勾选“Invert Call Tree”和“Hide System Libraries”复选标记,并检测代码中的问题所在。

之后你可以找到一些解决方案。

至少你可以尝试在为第二个 ScrollView 设置 contentOffset 属性之前添加额外的检查:

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    CGFloat contentOffsetForSecondScrollView = 123.0; // Calculate second scroll view content offset
    // Add additional check, if content offset doesn't change
    if (self.secondScrollView.contentOffset.y != contentOffsetForSecondScrollView) {
        self.secondScrollView.contentOffset = CGPointMake(0, contentOffsetForSecondScrollView);
    }
}

关于ios - -(无效)scrollViewDidScroll :(UIScrollView *)scrollView too slow in iOS 8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31980966/

相关文章:

ios - iPad SplitViewController - 使用 iPhone Storyboard ViewController

ios - 如何在 native react 中检测同时发生的 onPress 事件?

ios - 使用 UISegmentedControl 在 UITextField 上启用编辑

iphone - 在选择 UISearchDisplayController 后保持 UINavigationController 的导航栏隐藏

iphone - iOS 应用内购买和网络服务

ios - 将实例化的 UIView 从 NIB 约束到其他 UIView

iOS应用程序: Is it possible to figure if a user has bought a certain version of your app

ios - 用于 App Store 显示的 CFBundleDevelopmentRegion (info.plist) 的字符串格式

iphone - 测试应用程序是否确实从 UILocalNotification 变为事件状态

ios - NSURLConnection - 禁用身份验证质询响应机制