Note that there are some explanatory texts on larger screens.

plurals
  1. POChecking if the UIPickerView is shown or hidden? The *if* conditions?
    primarykey
    data
    text
    <p>I have a little problem with my UIPickerView animation. I did set up the animation so when I click a button the UIPickerView will slide up and after another click it will slide down. But I hit the problem on <em>if</em>. I tried to set up a new settings bool and set it's value after each animation, so the <em>if</em> was just checking for the bool. I'm not sure if I did explained it well, but maybe you get the idea from the code. But unfortunately it's not working... Any ideas?</p> <pre><code>- (void)viewDidLoad { [super viewDidLoad]; settings = [NSUserDefaults standardUserDefaults]; [settings setBool:NO forKey:@"pickerShown"]; [settings synchronize]; } - (IBAction)showPicker:(id)sender { CGRect rect = countryPicker.frame; CGPoint origin = CGPointMake(0, 510); // Some off-screen y-offset here. rect.origin = origin; countryPicker.frame = rect; if ([settings boolForKey:@"pickerShown"] == YES) { // Perform transform to slide it off the screen. [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.5]; countryPicker.transform = CGAffineTransformMakeTranslation(0, -0); // Offset. [UIView commitAnimations]; [settings setBool:NO forKey:@"pickerShown"]; [settings synchronize]; } else if ([settings boolForKey:@"pickerShown"] == NO) { // Perform transform to slide it onto the screen. [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.5]; countryPicker.transform = CGAffineTransformMakeTranslation(0, -266); // Offset. [UIView commitAnimations]; [settings setBool:YES forKey:@"pickerShown"]; [settings synchronize]; } } </code></pre> <p>EDIT:</p> <p>Just found the solution... If anyone's interested - here it is:</p> <p>The h. file:</p> <pre><code>. . . { BOOL pickerShown; } . . . </code></pre> <p>The .m file:</p> <pre><code>- (void)viewDidLoad { [super viewDidLoad]; CGRect rect = countryPicker.frame; CGPoint origin = CGPointMake(0, 510); // Some off-screen y-offset here. rect.origin = origin; countryPicker.frame = rect; pickerShown = NO; } - (IBAction)showPicker:(id)sender { if (pickerShown == NO) { // Perform transform to slide it onto the screen. [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:1]; //[UIView setAnimationDidStopSelector:@selector(hidePicker)]; countryPicker.transform = CGAffineTransformMakeTranslation(0, 0); // Offset. [UIView commitAnimations]; [self performSelector:@selector(hidePicker) withObject:nil afterDelay:1]; } else if (pickerShown == YES) { //countryPicker.hidden = NO; // Perform transform to slide it onto the screen. [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:1]; countryPicker.transform = CGAffineTransformMakeTranslation(0, -266); // Offset. [UIView commitAnimations]; countryPicker.hidden = NO; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload