我在登录视图控制器中成功导入了IQKeyboardManger。之后我添加了这段代码
//在viewDidLoad
中- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
//IQKeyboardManager
[[IQKeyboardManager sharedManager] setEnable:YES];
[[IQKeyboardManager sharedManager] setKeyboardDistanceFromTextField:100];
[[IQKeyboardManager sharedManager] setEnableAutoToolbar:YES];
[[IQKeyboardManager sharedManager] setShouldShowTextFieldPlaceholder:YES];
[self.ad.window makeKeyAndVisible];
}
但它在iOS 11.0中不起作用
屏幕1
屏幕2
我在app delegate中添加了代码
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil];
//Identify launching status(Is first time or not)
//If it is first time go to login page
if (![[NSUserDefaults standardUserDefaults] boolForKey:@"HasLaunchedOnce"]) {
self.lpvc = [self.mainStoryboard instantiateViewControllerWithIdentifier:@"LPVC"];
self.window.rootViewController = self.lpvc;
NSLog(@"Launched first time");
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"HasLaunchedOnce"];
[[NSUserDefaults standardUserDefaults] synchronize];
//IQKeyboarbManager
[[IQKeyboardManager sharedManager] setEnable:YES];
// [[IQKeyboardManager sharedManager] setKeyboardDistanceFromTextField:100];
[[IQKeyboardManager sharedManager] setEnableAutoToolbar:YES];
[[IQKeyboardManager sharedManager] setShouldShowTextFieldPlaceholder:YES];
} else {
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"loggedin"]) {
self.rvc = [self.mainStoryboard instantiateViewControllerWithIdentifier:@"RVC"];
self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:self.rvc];
NSLog(@"Already launched");
[self getDataFromServer];
// [self.rvc checkAppVersion];
}
}
[self.window makeKeyAndVisible];
return yes;
答案 0 :(得分:0)
将该代码复制到AppDelegate
AppDelegate.m
#import "AppDelegate.h"
#import "IQKeyboardManager.h"
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//ONE LINE OF CODE.
//Enabling keyboard manager(Use this line to enable managing distance between keyboard & textField/textView).
[[IQKeyboardManager sharedManager] setEnable:YES];
//(Optional)Set Distance between keyboard & textField, Default is 10.
//[[IQKeyboardManager sharedManager] setKeyboardDistanceFromTextField:15];
//(Optional)Enable autoToolbar behaviour. If It is set to NO. You have to manually create UIToolbar for keyboard. Default is NO.
[[IQKeyboardManager sharedManager] setEnableAutoToolbar:YES];
//(Optional)Setting toolbar behaviour to IQAutoToolbarBySubviews to manage previous/next according to UITextField's hierarchy in it's SuperView. Set it to IQAutoToolbarByTag to manage previous/next according to UITextField's tag property in increasing order. Default is `IQAutoToolbarBySubviews`.
//[[IQKeyboardManager sharedManager] setToolbarManageBehaviour:IQAutoToolbarBySubviews];
//(Optional)Resign textField if touched outside of UITextField/UITextView. Default is NO.
//[[IQKeyboardManager sharedManager] setShouldResignOnTouchOutside:YES];
//(Optional)Giving permission to modify TextView's frame. Default is NO.
//[[IQKeyboardManager sharedManager] setCanAdjustTextView:YES];
//(Optional)Show TextField placeholder texts on autoToolbar. Default is NO.
[[IQKeyboardManager sharedManager] setShouldShowTextFieldPlaceholder:YES];
[self.window makeKeyAndVisible];
return YES;
}
它会正常工作。
注意:确保您已更新到最新版本(5.0.3)