开发者

iPhone app entering back into foreground shifts the view back to its origins and keyboard is still visible

开发者 https://www.devze.com 2023-01-29 05:43 出处:网络
I\'m currently working on an iPhone 4 app with a registration view. The users can focus into a UITextField and I have code that will shift the view upwards to prevent the keyboard from covering up the

I'm currently working on an iPhone 4 app with a registration view. The users can focus into a UITextField and I have code that will shift the view upwards to prevent the keyboard from covering up the textfield. But if the app is backgrounded and brought back into the foreground again, the keyboard is still up, the textfield is still in focus, but the view is now shifted back down in its original state. This covers up the textfield.

What's going on? How do I either make the view stay put or hide the keyboard wh开发者_StackOverflow中文版en the app is brought back into the foreground?

UPDATE:

-Any changes for this on the new iOS5?


you could try doing something in applicationDidEnterBackground in your app delegate like

NSLog(@"%@", [self.viewController.YOURTEXTFIELD isFirstResponder]);
if ([self.viewController.YOURTEXTFIELD isFirstResponder]) {
    [self.viewController.YOURTEXTFIELD resignFirstResponder];
}

the "isFirstResponder" checks to see if the keyboard is currently being used in this view and returns YES if it is and NO if it isn't.

The NSLog is there just so you know what is getting passed into the if statement.


I've next solution:

In AppDelegate

- (void)applicationDidBecomeActive:(UIApplication *)application
{   

    // 1. get access to ViewController which is on top
    // In my case, I have navigation controller in root

    UIViewController* current_controller = [self.rootNavController.viewControllers lastObject];

    // 2. loop all uitextfield.
    for (UITextField* o_txt in [current_controller.view subviews]) {
        [o_txt resignFirstResponder];
    }

}

Look's like "hot fix" )

0

精彩评论

暂无评论...
验证码 换一张
取 消