0

テキストフィールドの背景を変更するだけの 2 つのフェード メソッドがあります。唯一の違いは、背景に使用される画像です。画像の名前はコピー アンド ペーストされているため、スペル ミスはありません。

- (IBAction)fadeEnable:(UITextField *)textField;
{

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.00];
[textField setAlpha:0];
[UIView commitAnimations];

textField.background = [UIImage imageNamed:@"background_for_text.png"];

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.00];
[textField setAlpha:1];
[UIView commitAnimations];

}

- (IBAction)fadeDisable:(UITextField *)textField;
{

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.00];
[textField setAlpha:0];
[UIView commitAnimations];

textField.background = [UIImage imageNamed:@"background_for_text_2"];

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.00];
[textField setAlpha:1];
[UIView commitAnimations];

}

"enabled@ プロパティが変更されたかどうかを確認する textField にオブザーバーがあります。

有効なプロパティが変更され、有効に変更された場合に有効なアニメーションを実行するというコードを少し書き込もうとしています。無効に変更された場合は、無効化されたアニメーションを実行します。

残念ながら、両方のシナリオで fadeDisabled メソッドしか実行しないため、理由がわかりません。

- (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *) context;
{


UITextField *txtField = (UITextField *)object;




BOOL new = [[change objectForKey:NSKeyValueChangeNewKey] boolValue];
BOOL old = [[change objectForKey:NSKeyValueChangeOldKey] boolValue];

NSLog(@"new,%i",new);
NSLog(@"old,%i",old);

if ((new != old) && (new == NO))
{

 [self fadeDisable:txtField];
}

else if ((new != old) && (new == YES))
{
 [self fadeEnable:txtField];
}

}
4

1 に答える 1

0

間違いを見つけました。fadeDisabled の場合、通常の背景ではなく、無効な背景を変更する必要があります。

以下を使用しましたが、現在は正常に機能しているようです。

textField.disabledBackground = [UIImage imageNamed:@"background_for_text_2"];
于 2013-06-26T14:44:40.020 に答える