iOS给类设置属性,是否禁用第三方键盘

iOS可以给类设置属性
iOS可以设置是否禁用第三方键盘,以及针对个别页面是否禁用第三方键盘

//为类别设置属性

@property (nonatomic,assign,class) BOOL useSystemKeyBoard;
+(void)setUseSystemKeyBoard:(BOOL)useSystemKeyBoard{
    objc_setAssociatedObject(self, @selector(useSystemKeyBoard), @(useSystemKeyBoard), OBJC_ASSOCIATION_ASSIGN);
}
+(BOOL)useSystemKeyBoard{
    NSNumber *useSystemKeyBoard =objc_getAssociatedObject(self, @selector(useSystemKeyBoard));
    return [useSystemKeyBoard boolValue];
}

//是否允许使用第三方键盘

- (BOOL)application:(UIApplication *)application shouldAllowExtensionPointIdentifier:(NSString *)extensionPointIdentifier NS_AVAILABLE_IOS(8_0)
{
    if ([extensionPointIdentifier isEqualToString:@"com.apple.keyboard-service"]) {
        if (UITextField.useSystemKeyBoard) {
            return NO;
        }
    }
    return YES;
}

//设置某个键盘不允许使用第三方键盘

- (void)textFieldDidBeginEditing:(UITextField *)textField{
    if (textField == self.topTxtFld) {
        UITextField.useSystemKeyBoard = YES;
    }else{
        UITextField.useSystemKeyBoard = NO;
    }
}
- (void)textFieldDidEndEditing:(UITextField *)textField{
    UITextField.useSystemKeyBoard = NO;
}

© 版权声明
THE END
如果内容对您有所帮助,就支持一下吧!
点赞0 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容