0

I already have the code to animate UIPickerView to act like iOS keyboard, but the problem is when it's loaded for the first time, the UIPickerView is already shows up. I want to hide it first outside UIView area, until UIButton tapped. so it will animate just like iOS keyboard.

here's the picture to illustrate what I mean :

enter image description here

how can it be done? thank you.

Saint Robson
  • 5,475
  • 18
  • 71
  • 118
  • 1
    are you saying that the picker view is loaded after the application is launched but you want to laod it after you tapped on the view.... – BalaChandra Sep 17 '13 at 11:57
  • actually, I have 2 UIView and UIPickerView is under the second UIView. not the first one. and it has Push animation between them. what I need is when I go to second UIView, the UIPickerView is hiding. and when I tap the button (on second UIView) the UIPickerView will show up. – Saint Robson Sep 17 '13 at 12:16

4 Answers4

1

Just set the frame of pickerView accordingly while initiating.

UIPickerView *pickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(100, 900, 200, 200)];

if you want pickerView to appear from bottom then increase the y co-ordinate and if you want pickerView to appear from right then increase the x co-ordinate value

if pickerView is on the UIView which is again on some UIViewController then set the ClipsToBounds to YES.

[yourView setClipsToBounds:TRUE];

Hope this will help you.

Prashant Nikam
  • 2,253
  • 4
  • 17
  • 29
  • I tried to use your code : _registerList = [[UIPickerView alloc] initWithFrame:CGRectMake(100, 900, 200, 200)]; but still UIPickerView perfectly sit on its position. nothing's change. I also modify the value of X (100) and Y (900), but again nothing's change... – Saint Robson Sep 17 '13 at 10:46
  • here's my UIPickerView on interface file : @property (strong, nonatomic) IBOutlet UIPickerView *registerList; – Saint Robson Sep 17 '13 at 10:47
  • 1
    its in viewDidLoad, thats ok....then I think you must be changing the frame somewhere else in your code, try debugging it and check the frame of pickerView.. – Prashant Nikam Sep 17 '13 at 10:53
  • Hi bro, thanks for your reply... But could you be more specific about 'changing the frame'? Should I add another UI component under UIPickerView and treated as frame? Thank you – Saint Robson Sep 17 '13 at 11:01
  • No no.... frame is the property that every UI Component has... by 'changing the frame' I meant that you must be doing [registerList setFrame:CGRectMake(100,100,100,100)] somewhere else in your code other that initialization...just check this thing – Prashant Nikam Sep 18 '13 at 05:06
1

Sorry i cant comment so answering from this I think you are already placed an UIpicker view in your view concept is same as @xman said. If you didnt place picker view place it

then in .h create property for picker view

@interface ViewController : UIViewController
{ 
 IBOutlet UIPickerView *statepicker;
}

@property (weak, nonatomic) IBOutlet UIView *statepickerview;

in .m first synthesize

@implementation ViewController

@synthesize statepickerview;

in viewdidLoad initially set frame of picker view out of view example

- (void)viewDidLoad
{

 statepickerview.frame = CGRectMake(-9, 506, 367, 263);
[super viewDidLoad];

}

then in action call the frame to visible postion

- (IBAction)ButtonPress:(id)sender {

    statepickerview.frame = CGRectMake(0, 250,321, 260);


}

when you press button if it is not visible then try to change the co-ordinates

If this not works properly check this link create view and place the picker view inside the custom view and change the frame size of the view see this link surely it will help

Yohan
  • 1,108
  • 9
  • 21
  • Hi Yohan, thanks for your reply. I did what you said, but my problem is always in viewDidLoad. those value (-9, 506, 367, 263) seems to be ignored by compiler. UIPickerView always placed right on the bottom of the screen. – Saint Robson Sep 17 '13 at 12:27
  • 1
    k k i edited the answer i shared an url check this video surely it will help – Yohan Sep 17 '13 at 12:31
  • 1
    set delegate, datasource and numberof compnent all then do the above – Yohan Sep 17 '13 at 12:36
  • I saw that YouTube video, but something I can't see there... do I have to import something in my .h / .m in order to make CGRectMake works? because I did exactly what video said, but still UIView (container) is not moving anywhere... – Saint Robson Sep 17 '13 at 12:58
  • 1
    no you don want to import anything i did the concept before some days it is worked. Have you kept the picker view in separate custom view – Yohan Sep 17 '13 at 13:04
  • I did... I will give an update for this problem in new post, because I found something weird with my Xcode.. hold on... I need to screenshot my mac... – Saint Robson Sep 17 '13 at 13:06
  • I put into simple Xcode project and it's not working, I know it sounds crazy, but it really happen... here's what I have : http://stackoverflow.com/questions/18850871/cgrectmake-is-not-working-with-uiview – Saint Robson Sep 17 '13 at 13:14
  • answer this questions so only i can solve have you add delegate and datasource for picker view – Yohan Sep 17 '13 at 13:16
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/37528/discussion-between-yohan-and-robert-hanson) – Yohan Sep 17 '13 at 14:04
0

You can set pickerview's y position with your window's height. Like this :

    [self.view addSubview:pickerView];
   pickerView.frame =  CGRectMake(0, appDelegate.window.frame.size.height,pickerView.frame.size.width,pickerView.frame.size.height)

You have to add pickerview in your view and then set frame of it.

Nirmalsinh Rathod
  • 5,079
  • 4
  • 26
  • 56
0

I found answer... case closed... it's all because of 'AutoLayout' is enabled on my XCode Project... when it's disabled, everything works as I expected.

Saint Robson
  • 5,475
  • 18
  • 71
  • 118