2011-10-18 16 views
3

私のUIPickerViewアニメーションに少し問題があります。 アニメーションを設定したので、ボタンをクリックするとUIPickerViewがスライドし、別のクリックの後にスライドします。しかし、私はの場合、の場合に問題に突き当たった。私は新しい設定boolを設定しようとしました。そして、各アニメーションの後に値を設定しました。なら、はブールをチェックしていました。私はそれをうまく説明したかどうかは分かりませんが、コードからそのアイデアを得るかもしれません。 残念ながら、それは動作していない...任意のアイデア?UIPickerViewが表示されているかどうかを確認していますか? * if *条件?

- (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]; 

    } 
} 

EDIT:誰もが興味を持っていた場合

ちょうどソリューション... を見つけた - ここにある:

時間。ファイル:

. 
. 
. 
{ 
BOOL pickerShown; 
} 
. 
. 
. 

.mファイル:

- (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; 

    } 
} 

答えて

1

ちょうど...解決策を見つけた - ここにある:

時間。ファイル:

. 
. 
. 
{ 
BOOL pickerShown; 
} 
. 
. 
. 

.mファイル:ビューが画面に表示されている

- (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; 

    } 
} 
0

あなたが望むすべてのピッカービューを表示する基本的な効果である場合には、再度それを削除するともっと簡単な方法があります。

擬似コード:誰もが興味を持っていた場合

//do any picker initialization here 

if(!pickerIsShowing) 
[self.view addSubview:yourPickerView]; 
else 
[self.yourPickerView removeFromSuperView]; 
+0

申し訳ありませんが、それは私が意味するものではありません。私は解決策を見つけました:) –

+0

@DomiNickHádl:他の人のためにソリューションを投稿してください。 – titaniumdecoy

+0

これはすでに最初の投稿にあります。私は答えとしてそれを追加します:) –

4

場合、それはwindowプロパティが非nilになります。

1

あなたはでそれを確認することができます。ピッカーはスーパービューがnilになり、その後表示されていない場合

self.countryPicker.superview 

。それ以外の場合はビューが含まれます。

+0

シンプルで効率的な - と卑劣な - 私はそれが好きです - 私のために完全に動作します - ありがとう – SimonTheDiver

関連する問題