4

This is sort of a follow-up to this issue: becomeFirstResponder slows down app

I'm experiencing the same problem as that poster, i.e. calling becomeFirstResponder seems to slow down my app (it hangs for maybe 1-2s). However, whereas they were calling it in conjunction with displaying an alert, I am simply trying to unhide a hidden view and have it appear with a certain field as the first responder. Something like:

[self.dialogView setHidden:NO];
[self.dialogText becomeFirstResponder];

The dialogView has a hierarchy that contains dialogText (the UITextField I'm trying to set as first responder) and some other items.

This slowness is only exhibited the first time this code is executed, i.e. the first time we try to open this dialog. On subsequent attempts, there is no obvious slowness (I assume this is because dialogText is already first responder at that point - I haven't used resignFirstResponder anywhere?).

Edit: here's some additional code for context, not sure it will really shed any more light though. Note I'm now animating the unhiding of this dialog view, however the behaviour is no different. I have also since moved the becomeFirstResponder call into the completion block (not reflected in the code here) so that at least the appearance of the dialog isn't delayed, however there is still a delay between the dialog appearing and the keyboard appearing.

- (IBAction)showEditDialog:(id)sender
{    
    [UIView animateWithDuration:0.3f animations:^() {
        self.maskView.alpha = 0.8;
        self.editDialogView.alpha = 1.0;
    } completion:^(BOOL finished) {
        if (finished) {
        }
    }];

   [self.editDialogText becomeFirstResponder];
}
Community
  • 1
  • 1
G.S.
  • 623
  • 6
  • 22
  • 1
    I added a bit more context above, not sure how much it will add though. Let me know if there's anything else you'd like to see – G.S. Oct 12 '12 at 16:37
  • 1
    Basis on your code, i can say after completion of your animation it will show keyboard, comment your animation code and then try. And let me know it, is still taking to much time for keyboard? – Mobile App Dev Oct 13 '12 at 04:42
  • Try to minimize your animation time also and see it make any difference or not. – Mobile App Dev Oct 13 '12 at 04:45
  • Like I said, before I had the appearance animated the same issue was occurring. The animation has nothing to do with it. – G.S. Oct 15 '12 at 03:39

1 Answers1

2

firstly, are you doing view switching?(e.g view1(hide)->view2(unhide))

If you having your dialogText(which I guess is a textfield?) on a different view, I suggest you do:

[self.view bringSubviewToFront:view2];

first

It's hard to guess what slows it down without looking at how your views are allocated and where your textView or textField are sitting on.

phil88530
  • 1,499
  • 3
  • 19
  • 27
  • The views hierarchy is: view->editDialogView(view)->editDialogText(texfield). So there is no view switching as such, the main view is always visible, we just hide/unhide editDialogView on top of it. I just gave [self.view bringSubviewToFront:self.editDialogView] a shot and it looks like it may just do the trick, will do a little more testing to confirm and report back. – G.S. Oct 17 '12 at 22:49
  • kk. let me know if it is the issue. And btw I like the name G.Moore, reminds me gary moore. lol – phil88530 Oct 17 '12 at 22:53
  • So I was a bit premature in thinking bringSubviewToFront fixed it. It doesn't actually seem to have any effect (I think I was used to the longer delay I had by putting becomeFirstResponder in the completion block of the unhiding animation). Any other ideas? – G.S. Oct 18 '12 at 00:13
  • Hey phil88530, any other ideas? – G.S. Oct 22 '12 at 20:25
  • Hey, sorry haven't login for few days. I realised you have a 0.3f second animation for alpha(transparent), I wonder if that's actually cause it? I personally would use a [NSTimer scheduledTimerWithTimeInterval:.....] to do it? if you want to give that a try? And just for my interest, would you tell me which iphone you are using?(which simulator or iPhone, what model you set and what ios version?) – phil88530 Oct 24 '12 at 18:27
  • because it's such a low alpha change(0.8 to 1.0 is tiny) and you actually spent 0.3 seconds to do it, logically, it should be fine but I wonder if that is actually result you vision uncomfortable. if not the case, you have to show me more codes to understand the entire logic.(sometimes slowdown is from somewhere else but only trigged when this action happens) – phil88530 Oct 24 '12 at 18:28