我有以下viewDidLoad方法:
- (void)viewDidLoad {
NSLog(@"didLoad");
if (self.loginField.text.length > 0) [self.passwordField becomeFirstResponder];
else [self.loginField becomeFirstResponder];
}我还在viewWillAppear和viewDidAppear中添加了日志时间。
在某些情况下,推送动画需要很长时间。我已经用注释(和没有) if-else行来度量时间(参见:时间显示在下面)。我不知道什么能减缓我的应用程序之间的viewWillAppear和viewDidAppear调用。
我试着用Time Profiler (仪器)对这段代码进行分析,但它什么也没有显示。我不知道该怎么做,以便更快地展示我的观点。有什么想法吗?
与becomeFirstResponder,first call
2014-07-11 16:51:41.090 didLoad
2014-07-11 16:51:41.133 willAppear
2014-07-11 16:51:44.223 did appear
diffAppear = 3090ms与becomeFirstResponder,第二次调用
2014-07-11 16:52:01.370 didLoad
2014-07-11 16:52:01.400 willAppear
2014-07-11 16:52:02.109 did appear
diffAppear = 709ms不带becomeFirstResponder,先调用
2014-07-11 16:57:21.720 didLoad
2014-07-11 16:57:21.754 willAppear
2014-07-11 16:57:22.420 did appear
diffAppear = 666ms不带becomeFirstResponder,第二次调用
2014-07-11 16:57:31.851 didLoad
2014-07-11 16:57:31.870 willAppear
2014-07-11 16:57:32.541 did appear
diffAppear = 671ms发布于 2014-07-11 16:27:12
评论中的@holex metion:
-becomeFirstResponser通常加载实际对象的输入视图,这需要时间。另一方面,在视图位于导航堆栈和视图-层次结构之后,您应该正确地调用该方法,这意味着在这种情况下:在-viewDidAppear:方法中或之后,不要更早。
我把–becomeFirstResponser搬到了-viewDidAppear:。现在,根据这个question,我添加了这些观察者,如下所示,现在它应该应用程序。
- (void)willShowKeyboard:(NSNotification *)notification {
[UIView setAnimationsEnabled:NO];
}
- (void)didShowKeyboard:(NSNotification *)notification {
[UIView setAnimationsEnabled:YES];
}
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willShowKeyboard:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didShowKeyboard:) name:UIKeyboardDidShowNotification object:nil];这不是一个完美的解决方案(推动画没有键盘),但对我来说已经足够好了。
https://stackoverflow.com/questions/24701220
复制相似问题