Pop up of UIPickerView

Discussion in 'iOS Programming' started by arnieterm, Feb 16, 2009.

  1. macrumors regular

    Aug 28, 2008
    Hi, this is what I am trying to do. I currently have a UIPickerView added to a subview on in my ViewController class. What I want to do to is to load this subview on the tap of UITextField and have it animate up instead of just magically pop out of nowhere.

    I want this subview to animate from the bottom to the middle of the screen like that of a keyboard. Any help/pointers would be much appreciated and thanks in advance!
  2. Guest


    Feb 17, 2003
    Hitchin, Herts, UK
    I've done this, it's not too hard - I just subclassed UIPickerView with some extra methods to scroll it up when it was made visible. Getting the animation to work right is the hardest bit. The one thing to think about is that a Picker View doesn't have a return key or any way to dismiss it when the user is finished...
  3. macrumors member


    Sep 22, 2008
    I have done this already, too. You should add a Toobar or something like that above/below the UIPicker. The animation is rather easy using UIViews beginAnimation/commitAnimation. The trick is to set the y-position below the screen first and then set it to the middle in the animation-block.
  4. macrumors 6502a

    Oct 24, 2008
    Just to put this (roughly) into code:

    CGRect rect = yourPicker.frame;
    CGPoint origin = CGPointMake(0, -100); // Some off-screen y-offset here.
    rect.origin = origin;
    yourPicker.frame = rect;
    // Perform transform to slide it onto the screen.
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.5];
    self.transform = CGAffineTransformMakeTranslation(0, 100); // Offset.
    [UIView commitAnimations];

Share This Page