這裏是問題 - 我有一個類,它是UIView(一張卡片)的子類。它自己創建一個按鈕,它調用changeStateIndicator:當用戶觸摸它時。UIButton在setImage之後不更新它的圖像:被調用
然後卡片必須在按下按鈕後翻動,按鈕應該改變它的顏色(實際上是圖像)。但它根本沒有發生,所以翻蓋在按鈕改變之前就開始了。這裏是我的代碼:
//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涉及到它的結束,但我不是很肯定這是實際的問題。請幫幫我。
你是否嘗試不調用方法prepareForTest來檢查按鈕是否會像你期望的那樣改變它的顏色? – tiguero 2012-07-24 21:47:05
也是如何延遲動畫 – tiguero 2012-07-24 21:59:34
沒有prepareForTest它工作正常)我知道,因爲我們正在同一個項目) – 2012-07-24 22:02:59