简体   繁体   English

在iPad Form Sheet上,响应时间非常慢

[英]On iPad Form Sheet very slow response time

I have the following problem: I have a Form Sheet presented modally with a UITextField on it. 我有以下问题:我有一个模态表,上面带有UITextField。 When tapping the UITextField, it takes about 3 secs until the Keyboard will show up, which is very slow. 点击UITextField时,大约需要3秒钟,直到键盘出现为止,这非常慢。 Does anybody have an idea what the problem could be? 有谁知道可能是什么问题?

-(BOOL)textFieldShouldReturn:(UITextField *)textField{
  if (textField == self.licenseTextField) {
    [self.licenseTextField resignFirstResponder];
  } return YES;
}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ [self.licenseTextField resignFirstResponder]; }

-(BOOL)disablesAutomaticKeyboardDismissal{ return NO; } 

iOS does not free memory for the keyboard unless it has to show the keyboard. iOS不会释放键盘的内存,除非必须显示键盘。 There are some workarounds, that are not exactly fancy but functional. 有一些变通办法,这些变通办法并不完全正确,但可以起作用。

This is a solution that I use. 这是我使用的解决方案。 I preload the keyboard on app start before showing the actual content of my app. 在显示应用程序的实际内容之前,我在应用程序启动时预装了键盘。 The starting process takes a little longer but at least my interface does not freeze when I show the keyboard later on. 启动过程需要花费更长的时间,但至少稍后显示键盘时,我的界面不会冻结。

// Update: Apple just rejected an app of mine using the method shown below for the second time, as it launches to a black screen on the iPad simulator (not the device!) sometimes, god knows why. //更新:Apple再次使用下面显示的方法拒绝了我的一个应用程序,因为它有时会在iPad模拟器(不是设备!)上启动到黑屏,上帝知道原因。

AppDelegate.m: AppDelegate.m:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{   
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidShow:) name:UIKeyboardDidShowNotification object:nil];

    UITextField *lagFreeField = [[UITextField alloc] init];
    [self.window addSubview:lagFreeField];
    [lagFreeField becomeFirstResponder];
    [lagFreeField resignFirstResponder];
    [lagFreeField removeFromSuperview];

    return YES;
}

- (void)keyboardDidShow:(NSNotification *) notification {
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardDidShowNotification object:nil];

    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, 0.2 * NSEC_PER_SEC);
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
        if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
            self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPhone" bundle:nil];
        } else {
            self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPad" bundle:nil];
        }

        self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:self.viewController];
        [self.window makeKeyAndVisible];
    });
}

The dispatch fixed some animation issues I had, maybe you don't need it. 调度程序修复了我遇到的一些动画问题,也许您不需要它。 More information on the problem and possible solutions. 有关该问题和可能的解决方案的更多信息。

Before applying any hack in source code, please test your app without debugging mode and without plugged in. A lot of iOS version has this issue. 在对源代码应用任何技巧之前,请在没有调试模式且没有插入的情况下测试您的应用。很多iOS版本都存在此问题。 When you test your app in real environment there will be no loading. 在真实环境中测试应用程序时,将不会加载任何内容。 Thanks 谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM