UIGestureRecognizer 在 << 时崩溃操作系统3.2

发布于 2024-10-01 16:14:16 字数 486 浏览 0 评论 0 原文

这是可以预料到的,但我似乎找不到一个可以正常工作的运行时,因为它之前似乎是一个私有 API!!!!

目前我已经并且 OS3.1.3 响应了 addGestureRecognizer 选择器!!!!

if ( [self.view respondsToSelector:@selector(addGestureRecognizer:)] ) {

        UIGestureRecognizer *recognizer;
        recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(morePress)];
        [self.view addGestureRecognizer:recognizer];
        recognizer.delegate = self;
        [recognizer release];


    }

This is to be expected but I can't seem to find a runtime that works properly as it seems it was a private API before!!!!

At the moment I have and OS3.1.3 responds to the addGestureRecognizer selector!!!!

if ( [self.view respondsToSelector:@selector(addGestureRecognizer:)] ) {

        UIGestureRecognizer *recognizer;
        recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(morePress)];
        [self.view addGestureRecognizer:recognizer];
        recognizer.delegate = self;
        [recognizer release];


    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

心安伴我暖 2024-10-08 16:14:16

您应该明确检查系统版本:

NSString *currentSystemVersion = [[UIDevice currentDevice] systemVersion];
if([currentSystemVersion compare:@"3.2"] == NSOrderedAscending) {
    //add gesture recognizer
} else {
    // :(
}

You should check for the system version explicitly:

NSString *currentSystemVersion = [[UIDevice currentDevice] systemVersion];
if([currentSystemVersion compare:@"3.2"] == NSOrderedAscending) {
    //add gesture recognizer
} else {
    // :(
}
挽袖吟 2024-10-08 16:14:16

iOS 3.2 之前不支持 UIGestureRecognizer。即使方法 addGestureRecognizer: 存在,也不意味着它可以安全使用。

UIGestureRecognizer is not supported prior to iOS 3.2. Even if the method addGestureRecognizer: exists, that doesn't mean it's safe to use.

初雪 2024-10-08 16:14:16

它确实是一个私有 api,3.2 之前的版本不支持。

苹果的文档说:

在运行时确定是否可以在以下位置使用手势识别器
您的应用程序,测试该类是否存在,如果存在,
分配一个实例并检查它是否响应选择器
视图中的位置:。这个方法直到 iOS 3.2 才被添加到类中。

示例代码:

UIGestureRecognizer *gestureRecognizer = [[UIGestureRecognizer alloc] initWithTarget:self action:@selector(myAction:)];

if (![gestureRecognizer respondsToSelector:@selector(locationInView:)]) {
    [gestureRecognizer release];
    gestureRecognizer = nil;
}
// do something else if gestureRecognizer is nil

说明:

确定某个类在给定 iOS 中运行时是否可用
发布时,您通常会检查该类是否为零。很遗憾,
此测试对于 UIGestureRecognizer 来说并不完全准确。虽然
这个类从 iOS 3.2 开始公开可用,它位于
在此之前的一小段时间内进行开发。尽管该类存在于
早期版本,它和其他手势识别器类的使用是
早期版本不支持。您不应该尝试使用
这些类的实例。

查看全文 此处

It was indeed a private api and not supported in versions prior to 3.2.

Apple's doc says:

To determine at runtime whether you can use gesture recognizers in
your application, test whether the class exists and, if it does,
allocate an instance and see check if it responds to the selector
locationInView:. This method was not added to the class until iOS 3.2.

Sample code:

UIGestureRecognizer *gestureRecognizer = [[UIGestureRecognizer alloc] initWithTarget:self action:@selector(myAction:)];

if (![gestureRecognizer respondsToSelector:@selector(locationInView:)]) {
    [gestureRecognizer release];
    gestureRecognizer = nil;
}
// do something else if gestureRecognizer is nil

Explenation:

To determine whether a class is available at runtime in a given iOS
release, you typically check whether the class is nil. Unfortunately,
this test is not cleanly accurate for UIGestureRecognizer. Although
this class was publicly available starting with iOS 3.2, it was in
development a short period prior to that. Although the class exists in
an earlier release, use of it and other gesture-recognizer classes are
not supported in that earlier release. You should not attempt to use
instances of those classes.

Check out the full text here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文