【问题标题】:On iPad Form Sheet very slow response time在 iPad 表单上,响应时间非常慢
【发布时间】:2014-08-06 04:24:47
【问题描述】:

我有以下问题:我有一个表单表单,上面有一个 UITextField。点击 UITextField 时,大约需要 3 秒才能显示键盘,这非常慢。有人知道问题可能是什么吗?

-(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; } 

【问题讨论】:

  • 在源代码中应用任何hack之前,请在没有调试模式和没有插入的情况下测试您的应用程序。很多iOS版本都有这个问题。当您在真实环境中测试您的应用程序时,将不会加载。谢谢

标签: ios forms uitextfield


【解决方案1】:

iOS 不会为键盘释放内存,除非它必须显示键盘。有一些变通方法,虽然不是很花哨但很实用。

这是我使用的解决方案。在显示我的应用程序的实际内容之前,我在应用程序启动时预加载键盘。启动过程需要更长的时间,但至少当我稍后显示键盘时我的界面不会冻结。

// 更新:Apple 刚刚使用下面显示的方法第二次拒绝了我的一个应用程序,因为它在 iPad 模拟器(不是设备!)上启动到黑屏有时,天知道为什么。

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];
    });
}

调度修复了我遇到的一些动画问题,也许你不需要它。 More information on the problem and possible solutions.

【讨论】:

  • 非常感谢!这已经解决了它,即使启动过程需要更长的时间。我仍然希望有一个没有变通办法的解决方案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-07-04
  • 1970-01-01
  • 1970-01-01
  • 2018-05-01
  • 2016-12-09
  • 2014-08-07
  • 1970-01-01
相关资源
最近更新 更多