簡體   English   中英

iOS:如何通過按下UIButton更改UIImageView

[英]iOS: How to change an UIImageView by pressing a UIButton

我的應用程序中有一個UIImageView和一個UIButton。 我想做的是,當用戶點擊UIButton時,UIImageView將更改為另一個圖像,然后幾乎立即返回到原始圖像。 模擬動畫。

編碼:

file.h

{

IBOutlet UIImageView *image1;
IBOutlet UIButton *button;

}

-(IBAction)button:(id)sender;

file.m

-(IBAction)button:(id)sender{


}

我必須在兩個文件中實現什么才能實現此目的?

任何幫助將不勝感激。 先感謝您!

當然。

將以下代碼插入“-(IBAction)button:(id)sender”中:

[UIView animateWithDuration:0.5f
                 animations:^{

                     image1.alpha = 0.1f;

                 } completion:^(BOOL finished) {

                     image1.image = [UIImage imageNamed:@"image2"]; // @"image2.png"

                     [UIView animateWithDuration:1.0f
                                      animations:^{

                                          image1.alpha = 1.0f;

                                      } completion:^(BOOL finished) {

                                          image1.image = [UIImage imageNamed:@"image1"];

                                      }];

                 }];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM