[英]How to drag and drop a UIButton
I have four UIButtons in my interface file. 我的界面文件中有四个UIButton。 I have outlets attached to each button.
我在每个按钮上都有插座。 I want to be able to drag and drop them across the screen.
我希望能够在屏幕上拖放它们。 What is the best way to do this?
做这个的最好方式是什么? How can I do this?
我怎样才能做到这一点? please help!!!
请帮忙!!!
There are 3 possibilities nowadays on how to enable items – that is UIViews and UIControls – to be draggable. 如今,关于如何使项目(即UIViews和UIControls)可拖动的可能性有3种。
try this u can drag and drop your button what ever you want 尝试此操作,您可以随意拖放按钮
implement this code in ViewDidLoad
在
ViewDidLoad
实现此代码
[self.shoeimageOutlet addTarget:self action:@selector(imageMoved:withEvent:) forControlEvents:UIControlEventTouchDragInside];
[self.shoeimageOutlet addTarget:self action:@selector(imageMoved:withEvent:) forControlEvents:UIControlEventTouchDragOutside];
it will call the method written below 它将调用下面编写的方法
- (IBAction) imageMoved:(id) sender withEvent:(UIEvent *) event
{
CGPoint point = [[[event allTouches] anyObject] locationInView:self.view];
UIControl *control = sender;
control.center = point;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.