Reputation: 13
I want to hide my UIPickerView when my app is loaded. but later on it will show / hide when button tapped.
So, I decided to put this code on viewDidLoad :
UIPickerView *pickerView = [[UIPickerView alloc] init];
float pvHeight = pickerView.frame.size.height;
float y = _screen.bounds.size.height - (pvHeight * -2);
_memberList.frame = CGRectMake(0 , y, pickerView.frame.size.width, pvHeight);
but when I run my app, it still there on default position. how to initially hide UIPickerView when it's loaded for the first time?
even if I manipulates value of y it still doesn't change anything... it's seems that there's something wrong with the code...
thank you.
UPDATE : I have this code to animate (show/hide) the UIPickerView later on using button, so what I need is initial position to be outside the screen when user runs the app. not Alpha = 0.
UIPickerView *pickerView = [[UIPickerView alloc] init]; // default frame is set
float pvHeight = pickerView.frame.size.height;
float y = _screen.bounds.size.height - (pvHeight); // the root view of view controller
[UIView animateWithDuration:0.5f delay:0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
_memberList.frame = CGRectMake(0 , y, pickerView.frame.size.width, pvHeight);
} completion:nil];
Upvotes: 0
Views: 1696
Reputation: 7685
It seems like you've enabled Auto Layout. If you're using Auto Layout, you shouldn't use the setFrame
method anymore, since Auto Layout while automatically do this for you.
You need to set up a constraint, probably a top space constraint in your case, and set the constant
property of that UILayoutConstraint
. So in your viewDidLoad
, you set the constant
so your view is outside of the window's bounds. And when the button is tapped, you animate the constant
to a value so the view appears inside the window's bounds.
Take a look at this question: Animating view with Auto Layout
Upvotes: 1
Reputation: 4272
into your viewDidLoad
write:
[yourView setAlpha:0];
when button pressed and you want to make it visible write this:
[UIView animateWithDuration:0.6 delay:0. options:UIViewAnimationOptionCurveEaseInOut animations:^{
[yourView setAlpha:1];
} completion:nil];
if you want to hide it again :
[UIView animateWithDuration:0.6 delay:0. options:UIViewAnimationOptionCurveEaseInOut animations:^{
[yourView setAlpha:0];
} completion:nil];
I hope it helps
Upvotes: 1
Reputation: 31647
How about this?
pickerView.hidden = YES;
and in action of tap show the UIPickerView.
pickerView.hidden = NO;
Hope this is what you are looking for.
Upvotes: 1