简体   繁体   中英

How to drag a image from one button to another button in iPhone?

Currently i am working in iPhone application, Using two buttons, then i set the image both button1 and button2, then i tried to drag a image from button1 to button2, Is it possible to do this? please help me

Thanks in Advance

 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]

You can get reference from this demo project.

it's very nice.

Also another link is here

There are more than one ways of doing this ...

  1. You can either create a UIImageView on the click event or action of button1 and use animation to drag that image till button2 where you make the imageview.image equal to button2's image , side by side making the original imageview as nil so that you can show it disappear into button2.

  2. Also, instead of buttons you can use UIImageViews directly and make and animation effect on the click methods there too.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM