2014-02-07 27 views
0

我使用setBackgroundImage:forState:像這樣進行着色我的背景圖像的顏色不同的狀態:setBackgroundImage:forState:animation/transition?

[myButton setBackgroundImage:genericImage forStates:UIControlStateNormal]; 
[myButton setBackgroundImage:buttonBackgroundPressed 
        forStates:UIControlStateHighlighted]; 

有動畫/淡入,直接應用輸入/輸出時間過渡到這種方法的一種手段?

+0

據我所知沒有。但你可以使用'[myButton addTarget:self action:@selector(fadeIn :) forControlEvents:UIControlEventTouchDownInside];'並將'[UIView animateWithDuration:animations:]'放到fadeIn方法中。 – crizztus

+0

@chris hrm ..似乎沒有工作。我會繼續玩。 – brandonscript

回答

1

這一次爲我的作品:

-(void) init{ 
    [myButton addTarget:self action:@selector(touchUp:) forControlEvents:UIControlEventTouchUpInside]; 
} 

- (void)touchUp:(id)sender 
{ 
    UIButton* btn = sender; 
    [UIView animateWithDuration:1.0 animations:^{ 
    btn.alpha = 0.5; 
    }]; 
} 
+0

是的,我也用alpha來處理 - 但還沒有動畫處理背景圖片。我懷疑我將需要使用默認(前景)圖像:| – brandonscript