如何使 UIbutton 在 UIView 中可拖动?
我需要在仪表板中拖放按钮我可以使用以下代码拖放按钮
- (void)viewDidLoad {
[super viewDidLoad];
[eventButton addTarget:self action:@selector(draggedOut:withEvent:)forControlEvents:UIControlEventTouchDragOutside |UIControlEventTouchDragInside];
}
- (void) draggedOut: (UIControl *) c withEvent: (UIEvent *) ev {
CGPoint point = [[[ev allTouches] anyObject] locationInView:self.view];
if(point.y > 22 && point.y <300)
c.center = CGPointMake(237, point.y - c.bounds.size.height/2 -5);
}
,但我需要在拖放时也需要更改按钮的位置
注意:我只为一个按钮编写了代码
请帮我解答我的问题
I need to drag and drop the button in my dash board i can drag and drop the button using the following code
- (void)viewDidLoad {
[super viewDidLoad];
[eventButton addTarget:self action:@selector(draggedOut:withEvent:)forControlEvents:UIControlEventTouchDragOutside |UIControlEventTouchDragInside];
}
- (void) draggedOut: (UIControl *) c withEvent: (UIEvent *) ev {
CGPoint point = [[[ev allTouches] anyObject] locationInView:self.view];
if(point.y > 22 && point.y <300)
c.center = CGPointMake(237, point.y - c.bounds.size.height/2 -5);
}
but i need while drag and drop i need to change the positions of the buttons too
note:i wrote the code only for one button
please help me for my question
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 UIButton 的 UIControlEventTouchDragInside 和 UIControlEventTouchUpInside 事件,例如
您可以使用 hbdraggablebutton 控件..
Use UIControlEventTouchDragInside and UIControlEventTouchUpInside events of UIButton like
You can use hbdraggablebutton control..