iOS可以給類設(shè)置屬性
iOS可以設(shè)置是否禁用第三方鍵盤郁惜,以及針對個別頁面是否禁用第三方鍵盤
//為類別設(shè)置屬性
@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;
}
//設(shè)置某個鍵盤不允許使用第三方鍵盤
- (void)textFieldDidBeginEditing:(UITextField *)textField{
if (textField == self.topTxtFld) {
UITextField.useSystemKeyBoard = YES;
}else{
UITextField.useSystemKeyBoard = NO;
}
}
- (void)textFieldDidEndEditing:(UITextField *)textField{
UITextField.useSystemKeyBoard = NO;
}