gpt4 book ai didi

uiscrollview - 在 iOS 5 模拟器上运行时,使用 iOS 6.0 SDK 和构建 iOS 5 Target 会导致 UIScrollView setMinimumZoomScale 失败

转载 作者:行者123 更新时间:2023-11-28 22:48:14 24 4
gpt4 key购买 nike

我升级到 Xcode 4.5 并开始使用 iOS SDK 6.0:enter image description here

我有一个用 Xcode 4.4 和 iOS SDK 5.1 开发的通用应用程序

enter image description here

并且它已经在所有经过测试的设备和模拟器上运行,没有出现任何故障。

希望它能继续在 iPhone 5 上运行,我想提供正确的启动图像并让它运行。

该应用程序的许多部分无需更改即可工作,但其中一部分不会:我放置在 UIScrollView 中的图像不会平移。这以前一直有效,但不适用于 iOS 6 模拟器。

问题的真正症结在于:当我在 iOS 5.0 或 iOS 5.1 模拟器上运行时,在我的调试日志中,我看到抛出如下异常:

-[NSKeyValueMethodSetter setMaximumNumberOfTouches:]: 无法识别的选择器发送到实例 0x6ddab20

堆栈爬取显示尝试进行此调用的代码是 UIScrollView setMinimumZoomScale

我调用 setMimimumZoomScale 的代码如下:

    CGFloat widthScale = self.scrollView.bounds.size.width / self.image.size.width;
CGFloat heightScale = self.scrollView.bounds.size.height / self.image.size.height;

// just reset the zoom scales; leave center and everything else where possible
self.scrollView.minimumZoomScale = MIN(1.0, MIN(widthScale, heightScale));
self.scrollView.maximumZoomScale = 4.0;

抛出的异常(和随后的崩溃)发生在第一次调用 setMimimumZoomScale 并显示上述消息时。

我猜测 Xcode 4.5 正在使用 setMinimumZoomScale 的代码调用发送该消息,它可能存在于 iOS 6 的库中,但在 iOS 5 中从未存在过。

其他人是否看到了类似的问题?

首先,我没有触及我的 .storyboard 文件,所以它们仍然可以在没有 autoLayout 的情况下工作。

我是否必须返回并在 Xcode 4.5 旁边安装 Xcode 4.4 才能继续维护我的工作应用程序?

最佳答案

回答我自己的问题......

我原来问题的复杂性涉及到额外的手势识别器。

在 iOS 5.1 SDK(和一些更早版本)下,可以向 UIScrollView 添加手势识别器,并能够让它与 UIScrollView 内置的 panGestureRecognizer 和 pinchGestureRecognizer 一起工作。

在 iOS 6.0 SDK 下,这种行为显然不再真正被支持。 relevant documentation并没有明确禁止该行为,因为它确实定义了 UIScrollView 将对可能与平移和捏合相关或无关的触摸执行的操作。

Because a scroll view has no scroll bars, it must know whether a touch signals an intent to scroll versus an intent to track a subview in the content. To make this determination, it temporarily intercepts a touch-down event by starting a timer and, before the timer fires, seeing if the touching finger makes any movement. If the timer fires without a significant change in position, the scroll view sends tracking events to the touched subview of the content view. If the user then drags their finger far enough before the timer elapses, the scroll view cancels any tracking in the subview and performs the scrolling itself. Subclasses can override the touchesShouldBegin:withEvent:inContentView:, pagingEnabled, and touchesShouldCancelInContentView: methods (which are called by the scroll view) to affect how the scroll view handles scrolling gestures.

为了纠正这个问题,我必须确保 Storyboard中的手势识别器不再是与 ScrollView 关联的集合的一部分,而是将它们与 ScrollView 的内容 View 相关联。

(在我的例子中,为了做到这一点,我必须使用 addGestureRecognizer: 为我感兴趣的每个手势识别器手动添加它们,因为内容 View 用于图像在 Storyboard 时不知道。)

关于uiscrollview - 在 iOS 5 模拟器上运行时,使用 iOS 6.0 SDK 和构建 iOS 5 Target 会导致 UIScrollView setMinimumZoomScale 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12636058/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com