简体   繁体   English

beginAnimations:context:不能使用颜色?

[英]beginAnimations:context: not working with color?

I am a little puzzled why the following is not working, button_ONE does a nice fade, but pressing button_TWO just snaps the color to black with no fade. 我有些困惑,为什么下面的命令不起作用,button_ONE会很好地淡入淡出,但是按下button_TWO只是将颜色捕捉为黑色而没有淡入淡出。

// FADES OUT OVER 1.5 Secs
- (IBAction)button_ONE:(id)sender {
    NSLog(@"FADE ALPHA");
    [textField_TOP_01 setAlpha:1.0];
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1.5];
    [textField_TOP_01 setAlpha:0.0];
    [UIView commitAnimations];
}

.

// IMMEDIATELY CHANGES TO BLACK
- (IBAction)button_TWO:(id)sender {
    NSLog(@"FADE COLOR");
    [textField_TOP_02 setTextColor:[UIColor redColor]];
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1.5];
    [textField_TOP_02 setTextColor:[UIColor blackColor]];
    [UIView commitAnimations];
}

Also this is using a subclass of UIViewController, I am also a little puzzled as to what UIView is refering / how its working. 同样,这是使用UIViewController的子类,对于UIView引用的内容/工作方式,我也有些困惑。

many thanks 非常感谢

Gary 加里

The textColor property of a UILabel is not an animatable property, so it's changes are not done as part of the animation. UILabel的textColor属性不是可设置动画的属性,因此它的更改不会作为动画的一部分进行。

The animation related methods on UIView are class methods rather than instance methods, so you call them on the class directly. UIView上与动画相关的方法是类方法,而不是实例方法,因此您可以在类上直接调用它们。 Check out the documentation on 'method type identifiers' at http://developer.apple.com/library/ios/#referencelibrary/GettingStarted/Learning_Objective-C_A_Primer/ . http://developer.apple.com/library/ios/#referencelibrary/GettingStarted/Learning_Objective-C_A_Primer/中查看有关“方法类型标识符”的文档。

beginAnimations:context:commitAnimations语句之间添加以下内容:

[UIView setAnimationTransition:UIViewAnimationTransitionNone forView:textField_TOP_02 cache:YES];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM