bar*_*one 7 security uitextfield ios ios8 ios-app-extension
如何让我的应用程序的UITextfields仅在iOS 8中使用Apple键盘?我不想允许第三方键盘,期间.我理解这可能是糟糕的用户体验所以请不要与我讨论这一点:)
我知道我可以将securedEntry属性设置为true以强制Apple键盘(http://www.imore.com/custom-keyboards-ios-8-explained).也许iOS 8会让我设置这个属性而不掩盖文本?
Joe*_*Tam 18
Apple正是为此提供了一个API.把它放在你的AppDelegate
- (BOOL)application:(UIApplication *)application
shouldAllowExtensionPointIdentifier:(NSString *)extensionPointIdentifier
{
if ([extensionPointIdentifier isEqualToString:@"com.apple.keyboard-service"]) {
return NO;
}
return YES;
}
Run Code Online (Sandbox Code Playgroud)
这是最干净,最有记录的方法:)
通过将 UITextView 或 UITextField 的属性设置为Secure Text Entryto YES,默认情况下将不会显示自定义键盘,也无法切换到。
不幸的是,这也会隐藏按键信息,并覆盖和禁用自动大写字母以及自动更正和拼写建议。NO因此,在强制用户使用 Apple 键盘后,您必须将其切换回原来的状态。
打开然后关闭此属性可以强制 Apple 键盘成为默认显示的第一个键。
\n\n现在,用户仍然可以按全局键,因此您有两个选择:
\n\n\xe2\x80\xa2One,你可以让他们检测他们是否使用[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(inputModeDidChange:) name:@"UITextInputCurrentInputModeDidChangeNotification"\n object:nil];,然后重新循环上面的 secureTextEntry 代码并强制切换回 Apple 默认键盘(不专业的方法,但很容易编程)。(*注意!这还将阻止用户使用听写键盘(单击空格键旁边的麦克风图标按钮),除非您使用未记录的代码来检测它是否是听写(确实存在并且据说已经通过了几个帐户的 Apple 验证。有关此信息可以在此处找到)\n
\n或者\n
\n\xe2\x80\xa2二:使用 UIWindows 获取默认键盘的 ONTOP 并添加一个 UIWindowuserInteractionEnabled设置为YES覆盖该键的位置(这将需要一些条件语句来确保您覆盖每种可能性的正确“更改键盘键”。(即横向键盘 iPhone4、纵向键盘 iPhone5 等)。
这是一些适用于纵向键盘(iphone5 和 iphone4)的演示代码\n
\nviewController.h
#import <UIKit/UIKit.h>\n\n@interface ViewController : UIViewController <UITextFieldDelegate> {\n\n UITextField *theTextField;\n UIWindow *statusWindow;\n\n}\n\n@end\nRun Code Online (Sandbox Code Playgroud)\n\n视图控制器.m
\n\n#import "ViewController.h"\n\n@interface ViewController ()\n\n@end\n\n@implementation ViewController\n\n- (void)viewDidLoad {\n [super viewDidLoad];\n // Do any additional setup after loading the view, typically from a nib.\n\n\n theTextField = [[UITextField alloc] initWithFrame:CGRectMake(50, 50, 50, 250)];\n [theTextField becomeFirstResponder];\n theTextField.secureTextEntry = YES;//turn back OFF later (like in `viewDidAppear`) and reset textField properties to YES (like auto correct, auto caps, etc).\n theTextField.delegate = self;\n [self.view addSubview:theTextField];\n\n\n\n //UIWindow *statusWindow; MUST be defined in .h file!\n statusWindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];\n statusWindow.frame = CGRectMake(37, self.view.frame.size.height-47, 45, 45);\n statusWindow.windowLevel = UIWindowLevelStatusBar;\n statusWindow.hidden = NO;\n statusWindow.backgroundColor = [UIColor clearColor];\n\n UIButton *keyboardCover = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 45, 45)];\n keyboardCover.backgroundColor = [UIColor redColor];\n [statusWindow addSubview:keyboardCover];\n\n //statusWindow.alpha = 1.00;\n statusWindow.userInteractionEnabled = YES;\n [statusWindow makeKeyAndVisible];\n\n\n}\n\n-(void)viewDidAppear:(BOOL)animated {\n [theTextField resignFirstResponder];\n theTextField.secureTextEntry = NO;\n theTextField.autocorrectionType = 2;//ON\n theTextField.autocapitalizationType = 2;//ON\n theTextField.spellCheckingType = 2;//ON\n [theTextField becomeFirstResponder];\n}\n\n\n\n- (void)didReceiveMemoryWarning\n{\n [super didReceiveMemoryWarning];\n // Dispose of any resources that can be recreated.\n}\n\n@end\nRun Code Online (Sandbox Code Playgroud)\n\n
\n下面是该代码的示例...我使用的是自定义键盘,当我启动应用程序时,它强制我使用 Apple 键盘,然后在“更改键盘”按钮上放置一个红色方块,这使我无法单击按钮来更改键盘。(红色方块当然可以更改为任何内容,例如空白键或处于褪色(禁用)状态的地球图标。)
\n
| 归档时间: |
|
| 查看次数: |
4063 次 |
| 最近记录: |