这是问题 - 我有一个类,它是 UIView 的子类(一张卡片)。它在自身上创建一个按钮,并在用户触摸它时调用 changeStateIndicator:。
然后在按下按钮后卡片必须翻转,并且按钮应该改变它的颜色(实际上是图像)。但它根本没有发生,所以翻转在按钮改变之前开始。这是我的代码:
//Adding a button to my view
UIButton *changeStateButton = [UIButton buttonWithType:UIButtonTypeCustom];
[changeStateButton setImage:[UIImage imageNamed:imageToInitWith] forState:UIControlStateNormal];
[changeStateButton setImage:[UIImage imageNamed:imageToInitWith] forState:UIControlStateHighlighted];
changeStateButton.frame = CGRectMake(0, 0, 30, 30);
changeStateButton.center = CGPointMake(self.bounds.size.width/2+([myWord length]*8)+17, 35);
changeStateButton.tag = 77;
[changeStateButton addTarget:self action:@selector(changeStateIndicator:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:changeStateButton];
//Method which is called when the button is touched
- (void)changeStateIndicator:(UIButton *)sender
{
[sender setImage:[UIImage imageNamed:@"StateYellow"] forState:UIControlStateNormal];
[sender setImage:[UIImage imageNamed:@"StateYellow"] forState:UIControlStateHighlighted];
currentWord.done = [NSNumber numberWithInt:currentWord.done.intValue-10];
[self prepareForTest];
}
//Method which flips the card
- (void)prepareForTest
{
testSide = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"cal_small3"]];
[UIView transitionFromView:self toView:testSide duration:0.5 options:UIViewAnimationOptionTransitionFlipFromRight completion:nil];
}
我的猜测是发件人在方法 -changeStateIndicator 结束之前不会更改其图像,但我不太确定这是实际问题。请帮帮我。