Search code examples
objective-cios4uipickerviewuiactionsheet

UIPickerView in an actionsheet in landscape


I display a picker view in an actionsheet in my iPhone app; that is, I have a button in a view which triggers an actionsheet that holds a picker view. It works great, except when the user rotates the device. When the user displays the view in landscape mode and then touches the button for the actionsheet, the pickerview does appear, but it looks jacked up. On the other hand, when the user loads the view in portrait mode and then touches the button which prompts the actionsheet, it looks ok. Any thoughts as to what might be going on here? This is when the user opens the actionsheet from a view that's already in landscape mode

This is how it looks when the user opens the view in portrait, and then turns the device to landscape


Solution

  • Make sure you configure the bounds of the action sheet and the frame of the pickerview to suit the orientation you're using.

    I'm using the following settings for landscape:

    [self.sheet setBounds:CGRectMake(0, 0, 480, 400)];
    CGRect pickerFrame = CGRectMake(0, 40, 480, 180);
    closeButton.frame = CGRectMake(420, 7.0f, 50.0f, 30.0f);
    

    And the following for portrait:

    [sheet setBounds:CGRectMake(0, 0, 320, 500)];
    CGRect pickerFrame = CGRectMake(0, 40, 0, 0);
    closeButton.frame = CGRectMake(260, 7.0f, 50.0f, 30.0f);
    

    Good luck!

    //Seto