Search code examples
iosuilabeluisplitviewcontrollerautolayout

Search Bar Loses FirstResponder when rotated from Portrait to Landscape mode


I'm trying to mimic the iPad Mail app. In portrait mode, when the popover's searchbar has first responder and I rotate to landscape, the popover's searchbar loses first responder. I want to continue giving the search bar first responder in landscape mode when it has first responder in portrait mode. How can I do this?

Portrait mode: http://postimg.org/image/kwjs9xkcx/

After Rotation: http://postimg.org/image/al7fh9snl/ Notice that the searchbar resigns first responder.

Thanks!


Solution

  • inside the method that deals with roation of the view

     - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation;
    

    check to see what interface you are in

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    
        if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
             [searchBar becomeFirstResponder];
        }
    }
    

    hope that helps!