如何在iPhone中将图像从一个按钮拖动到另一个按钮



目前我在iPhone应用程序中工作,使用两个按钮,然后我同时设置了按钮1和按钮2的图像,然后我尝试将图像从按钮1拖到按钮2,可以这样做吗? 请帮助我

提前致谢

 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]

您可以从此演示项目中获取参考。

很不错。

另一个链接也在这里

有不止一种方法可以做到这一点...

  1. 您可以在 button1 的单击事件或操作上创建一个UIImageView,并使用动画将该图像拖动到 button2,在那里您使imageview.image等于 button2 的图像,并排使原始图像视图为 nil,以便您可以显示它消失在 button2 中。

  2. 此外,您可以直接使用UIImageViews而不是按钮,并在那里的单击方法上制作和动画效果。

相关内容

最新更新