I imported IQKeyboardManger successfully in my login view controller. After that I added this code
我在登录视图控制器中成功导入了IQKeyboardManger。之后,我添加了这个代码。
//In viewDidLoad
/ /在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];
}
But it's not working in iOS 11.0
但在ios11.0中不能运行
Screen 1
屏幕1
Screen 2
屏幕2
I added code in app delegate
我在app委托中添加了代码
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;
1 个解决方案
#1
0
Copy that code to AppDelegate
将该代码复制到AppDelegate。
AppDelegate.m
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;
}
and it will work fine.
它会工作的很好。
Note : Make sure you have update to latest version (5.0.3)
注意:请确保更新了最新版本(5.0.3)
#1
0
Copy that code to AppDelegate
将该代码复制到AppDelegate。
AppDelegate.m
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;
}
and it will work fine.
它会工作的很好。
Note : Make sure you have update to latest version (5.0.3)
注意:请确保更新了最新版本(5.0.3)