使用iOS 6.0 SDK并为iOS 5构建目标导致UIScrollView setMinimumZoomScale在iOS 5模拟器上运行时失败 [英] using iOS 6.0 SDK and building for iOS 5 Target causes UIScrollView setMinimumZoomScale to fail when running on iOS 5 simulator

查看:154
本文介绍了使用iOS 6.0 SDK并为iOS 5构建目标导致UIScrollView setMinimumZoomScale在iOS 5模拟器上运行时失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已升级到Xcode 4.5并已开始使用iOS SDK 6.0:



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





并且它已经在所有设备和模拟器上运行没有任何故障。



希望能继续使用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;

//只需重置缩放比例;离开中心和其他可能的地方
self.scrollView.minimumZoomScale = MIN(1.0,MIN(widthScale,heightScale));
self.scrollView.maximumZoomScale = 4.0;

在第一次调用setMimimumZoomScale时发生抛出异常(以及随后的崩溃),并带有上述消息。



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

还有其他人看到类似的问题吗?



fwiw,我还没有触及我的.storyboard文件,所以他们会仍然设置为没有autoLayout工作。



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

解决方案

回答我自己的问题...



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



在iOS 5.1 SDK(以及之前的一些)中,可以向UIScrollView添加手势识别器并且能够使其工作在...中使用内置于UIScrollView中的panGestureRecognizer和pinchGestureRecognizer进行操作。



在iOS 6.0 SDK下,显然不再支持此行为。 相关文档并非如此很明确地禁止这种行为,因为它确定了UIScrollView将对可能与平移和捏合相关的触摸做什么。


因为滚动视图没有滚动条,所以它必须知道触摸是否表示滚动意图与跟踪内容中的子视图的意图。为了做出这种确定,它通过启动计时器暂时拦截触碰事件,并且在计时器触发之前,查看触摸手指是否进行任何移动。如果计时器在没有显着位置变化的情况下触发,则滚动视图将跟踪事件发送到内容视图的触摸子视图。如果用户在计时器过去之前将手指拖得足够远,则滚动视图会取消子视图中的任何跟踪并执行滚动操作。子类可以覆盖touchesShouldBegin:withEvent:inContentView:,pagingEnabled和touchesShouldCancelInContentView:方法(由滚动视图调用),以影响滚动视图处理滚动手势的方式。


为了纠正问题,我必须确保故事板中的手势识别器不再是与scrollview相关联的集合的一部分,而是将它们与内容视图相关联。滚动视图。



(在我的情况下,为了做到这一点,我必须使用 addGestureRecognizer手动添加它们:对于我感兴趣的每个手势识别器,因为内容视图适用于在故事板时间未知的图像。)


i upgraded to Xcode 4.5 and have started using the iOS SDK 6.0:

i have a universal app that had been developed with Xcode 4.4 and the iOS SDK 5.1

and it had been running on all devices and simulators tested without any glitches.

in hope of having it continue to work on the iPhone 5, i wanted to provide the proper launch-image and let it run.

many parts of the app work without changes, but one part of it does not: an image that i have placed in a UIScrollView does not pan. this has always worked previously, but not on the iOS 6 simulator.

to the real crux of the problem, though: when i went to run on the iOS 5.0 or iOS 5.1 simulators, in my debug log, i am seeing an exception thrown as follows:

-[NSKeyValueMethodSetter setMaximumNumberOfTouches:]: unrecognized selector sent to instance 0x6ddab20

the stack crawl shows that the code attempting to make this call is UIScrollView setMinimumZoomScale.

my code to call setMimimumZoomScale is as follows:

    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;

the thrown exception (and subsequent crash) occur on that first call to setMimimumZoomScale with the message noted above.

i am guessing that Xcode 4.5 is using code for setMinimumZoomScale that calls sends that message, which probably exists in the library for iOS 6, but never did in iOS 5.

are others seeing a similar problem?

fwiw, i have not touched my .storyboard files, so they would still be set to work without autoLayout.

do i have to go back and install Xcode 4.4 beside Xcode 4.5 in order to be able to continue to allow my working app to be maintained?

解决方案

answering my own question …

the complexity of my original question involved additional gesture recognizers.

under iOS 5.1 SDK (and some prior), it was possible to add a gesture recognizer to UIScrollView and be able to have it work in conjunction with panGestureRecognizer and pinchGestureRecognizer that are built into the UIScrollView.

under iOS 6.0 SDK, this behavior is apparently no longer really supported. the relevant documentation does not so much explicitly forbid the behavior as it does define what the UIScrollView will do for touches that may or may not be related to pan and pinch.

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.

in order to rectify the problem, i had to make sure that the gesture recognizers in the storyboard are no longer part of the collection associated with the scrollview, and instead associate them with the content-view of the scrollview.

(in my case, in order to do this, i had to manually add them using addGestureRecognizer: for each gesture-recognizer i am interested in, since the content-view is for images that aren't known at storyboard time.)

这篇关于使用iOS 6.0 SDK并为iOS 5构建目标导致UIScrollView setMinimumZoomScale在iOS 5模拟器上运行时失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆