如何在整个应用程序中禁用

如何在整个应用程序中禁用

本文介绍了如何在整个应用程序中禁用 iOS 11 拖动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出于安全原因,我想禁用新的 iOS 11 拖动 &在我的整个应用程序中删除功能.更具体地说是拖动部分.

For security reasons I want to disable the new iOS 11 drag & drop feature within my whole app. More specifically the drag part.

在 iOS 11 中,默认情况下,所有可以选择文本的地方的文本都会发生这种情况 - 弹出窗口、文本视图、网络视图等.

In iOS 11 it's happening by default for text in all places where text can be selected - popups, textviews, webviews, etc.

推荐答案

找到了解决方案.这是在您的应用程序可能需要的情况下,对 UIDragInteraction 的 isEnabled 方法进行方法调配以返回 NO.请注意,通常使用 swizzle 方法不是一个好主意.

Found a solution. It is to method swizzle the isEnabled method of UIDragInteraction to return NO in the situations your app may need. Note that normally it's not a good idea to method swizzle.

@implementation UIDragInteraction (TextLimitations)
+ (void)load
{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{

        Class class = [self class];

        SEL originalSelector = @selector(isEnabled);
        SEL swizzledSelector = @selector(restrictIsEnabled);

        Method originalMethod = class_getInstanceMethod(class, originalSelector);
        Method swizzledMethod = class_getInstanceMethod(class, swizzledSelector);

        BOOL didAddMethod =
        class_addMethod(class,
                        originalSelector,
                        method_getImplementation(swizzledMethod),
                        method_getTypeEncoding(swizzledMethod));

        if (didAddMethod) {
            class_replaceMethod(class,
                                swizzledSelector,
                                method_getImplementation(originalMethod),
                                method_getTypeEncoding(originalMethod));
        } else {
            method_exchangeImplementations(originalMethod, swizzledMethod);
        }
    });
}

-(BOOL)restrictIsEnabled
{
    if (restrictedCondition)
    {
        return NO;
    }
    return [self restrictIsEnabled];
}

这篇关于如何在整个应用程序中禁用 iOS 11 拖动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 06:39