如果你想淡出/淡入淡出按鈕的動畫我可以取代你自定義按鈕與UIImageView有相同的背景圖像作爲你最初的UIBUTTON.This將是第一件事,以在行動中的按鈕。當按鈕被替換爲uiview時,可以將淡出動畫應用於UIImageview,從最初的backgorund圖像到新的(選定的版本)。當動畫結束時,在完成塊中開始另一個動畫,將選定的圖像淡出爲正常背景圖像。然後第二個動畫結束刪除你的圖像並添加按鈕。
//聲明你的UIImageViews作爲高德
UIImageView *imageViewnormal = [[UIimageView alloc] initWithImage:normalIamge];
UIImageView *imageViewhighlighted = [[UIimageView alloc] initWithImage:highlightImage];
在操作您的按鈕
// make your button invisible
yourbutton.alpha = 0;
//add to same rect 2 imageviews with initial and selected backgrounds of uibutton
imageViewnormal.alpha = 1;
imageViewhighlighted.alpha = 0;
[self.view addSubview:imageViewhighlighted];
[self.view addSubview:imageViewnormal];
// newImageViewWithInitialBackground needs to be inserted secondly and alpha value 1
// newImageViewWithSelectedBackground has alpha 0 and is behind newImageViewWithInitialBackground
[UIView animateWithDuration:0.3
animations:^
{
imageViewnormalalpha = 0;
imageViewhighlighted.alpha = 1;
}
completion:^(BOOL finished)
{
}];
的UIControlEventTouchDown
在行動UIControlEventTouchUpInside您的按鈕
[UIView animateWithDuration:0.3
animations:^
{
imageViewnormal.alpha = 1;
imageViewhighlighted.alpha = 0;
}
completion:^(BOOL finished)
{
//Remove both of the uiimageviews aand make your button visible
[imageViewnormal removeFromSuperview];
[mageViewhighlighted removeFromSuperview];
yourbutton.alpha = 1;
}];
你的意思是你想改變選擇或取消選擇按鈕的圖像布頓...? –
只是綁定您的圖像的動畫事件在您的按鈕的觸摸和觸及事件... – HarshIT
我有一個按鈕。按下時,我想讓它的圖像更改爲其他指定圖像的動畫。在touchup我想讓它再次成爲原始圖像的動畫。 – Lukas