2013-03-29 63 views
2

我想動畫的圖像UIButton。動畫運行正常,但之後它總是在按鈕上放上灰色色調(,好像它是突出顯示/選中)。iOS - 動畫UIButton ImageView圖像導致按鈕被選中後

代碼:

NSArray *images = [[NSArray alloc] init]; 
images = [NSArray arrayWithObjects: 
      [UIImage imageNamed:IMAGE1], 
      [UIImage imageNamed:IMAGE2], 
      [UIImage imageNamed:IMAGE3], 
      [UIImage imageNamed:IMAGE4], 
      nil]; 
iconBobble.imageView.animationImages = images; 
iconBobble.imageView.animationDuration = 1.5; 
iconBobble.imageView.animationRepeatCount = 1; 
[iconBobble.imageView startAnimating]; 
+0

可能是你有圖像的灰度,從而停留在動畫的結尾。 。? – iphonic

回答

7

adjustsImageWhenHighlighted屬性將解決您的問題。

此代碼將解決你的問題....

-(IBAction)animateButton:(id)sender 
{ 
    [iconBobble setAdjustsImageWhenHighlighted:NO]; 

    NSArray *images = [[NSArray alloc] init]; 
    images = [NSArray arrayWithObjects: 
       [UIImage imageNamed:IMAGE1], 
       [UIImage imageNamed:IMAGE2], 
       [UIImage imageNamed:IMAGE3], 
       [UIImage imageNamed:IMAGE4], 
       nil]; 

    float animationDuration = 1.5; 
    iconBobble.imageView.animationImages = images; 
    iconBobble.imageView.animationDuration = animationDuration; 
    iconBobble.imageView.animationRepeatCount = 1; 
    [iconBobble.imageView startAnimating]; 
    [self performSelector:@selector(stopButtonAnimation) withObject:nil afterDelay:animationDuration]; 
} 
-(void)stopButtonAnimation 
{ 
    [iconBobble.imageView stopAnimating]; 
} 

這是工作正常,我:-)

+0

太棒了!那就是訣竅。一方面說明,我不需要包含'stopButtonAnimation'方法或調用。動畫自行停止。也許你有其他代碼作爲你的回調執行,但是動畫會在指定時間後自行停止。乾杯! – JimmyJammed

0

yourButton.backgroundColor = [UIColor clearColor];