[英]How to drag a image from one button to another button in iPhone?
目前,我在iPhone應用程序中工作,使用兩個按鈕,然后我同時設置了button1和button2的圖像,然后嘗試將圖像從button1拖到button2,是否可以這樣做? 請幫我
提前致謝
button1 = [UIButton buttonWithType:UIButtonTypeCustom];
[button1 setImage:[UIImage imageNamed:@"hearta.png"] forState:UIControlStateNormal];
button1.frame=CGRectMake(10, 60, 50, 50);
[button1 addTarget:self action:@selector(Button1Method) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button1];
button2 = [UIButton buttonWithType:UIButtonTypeCustom];
[button2 setImage:[UIImage imageNamed:@"club4.png"] forState:UIControlStateNormal];
button2.frame=CGRectMake(61, 60, 50, 50);
[button2 addTarget:self action:@selector(Button2Method) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button2]
有多種方法可以做到這一點...
您可以在button1的click事件或動作上創建UIImageView
,然后使用動畫將該圖像拖動到button2,使imageview.image
等於button2的image,並排將原始imageview設置為nil以便可以顯示它消失在button2中。
另外,除了按鈕之外,您還可以直接使用UIImageViews
並在其中的click方法上制作效果和動畫效果。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.