Pop up of UIPickerView

Discussion in 'iPhone/iPad Programming' started by arnieterm, Feb 16, 2009.

  1. macrumors regular

    Joined:
    Aug 28, 2008
    #1
    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

    caveman_uk

    Joined:
    Feb 17, 2003
    Location:
    Hitchin, Herts, UK
    #2
    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

    chbeer

    Joined:
    Sep 22, 2008
    Location:
    Berlin
    #3
    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

    Joined:
    Oct 24, 2008
    Location:
    Cambridge
    #4
    Just to put this (roughly) into code:

    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