我有一些UIButtons值。我通过以下代码动态创建的每个按钮:
-(void)AddNewTable: (NSString *) tablePic: (NSString *) addedType {
CreatedTable *ct = [[CreatedTable alloc] init];
CFUUIDRef newUniqueId = CFUUIDCreate(kCFAllocatorDefault);
NSString * uuidString = (__bridge NSString*)CFUUIDCreateString(kCFAllocatorDefault, newUniqueId);
CFRelease(newUniqueId);
UIImage *tableImage = [UIImage imageNamed: tablePic];
CGRect frameBtn = CGRectMake(160.0f, 160.0f, tableImage.size.width, tableImage.size.height);
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setBackgroundImage: tableImage forState:UIControlStateNormal];
[button setFrame:frameBtn];
[button addTarget:self action:@selector (draggedOut:withEvent::) forControlEvents:UIControlEventTouchDragInside];
[button setTitle: [NSString stringWithFormat:@"%d", tables.count] forState: UIControlStateNormal];
ct.Id = [uuidString lowercaseString];
ct.posX = 160;
ct.posY = 160;
ct.isActive = true;
ct.Index = button.titleLabel.text;
ct.picture = [NSString stringWithFormat:@"tables/%@", tablePic];
ct.type = addedType;
ct.angle = 0.0;
[tables addObject:ct];
[hallView addSubview:button];
}
CreatedTable - 是NSObject,带有创建按钮的字符串参数。
如您所见,我正在为每个创建的按钮添加选择器。我可以通过这个选择器移动每个按钮。这是代码:
- (IBAction)draggedOut: (id)sender withEvent: (UIEvent *) event: (NSSet *)touches {
CreatedTable = [tables objectAtIndex: selected.[titleLabel.text intValue]]
UIButton *selected = (UIButton *)sender;
selected.center = [[[event allTouches] anyObject] locationInView:hallView];
ct.posX = selected.center.x;
ct.posY = selected.center.y; // Here I'm changing params in ct.
}
现在我需要实现多选(通过点击它们来选择一些按钮值,使组成一个王)然后我需要将这个组(所有选定的按钮)移动到一个单个对象。 / p>
有任何建议如何实现它?
答案 0 :(得分:0)
您可以为AddNewTable中的每个按钮设置不同的标记,如下所示:
[button setTag:];
然后在draggedOut中你可以通过以下方式找到它:
[发件人标签]
答案 1 :(得分:0)
当用户逐个选择多个按钮时,通过更改其背景图像将所有选定的按钮标记出来。现在,当用户开始拖动任何一个所选按钮时,创建所有Bigger视图(使用清晰的背景颜色)并添加所有选定按钮的副本(新按钮看起来与所选按钮相似),并将它们添加到更大的视图中。现在改变原始按钮的位置(按钮被拖动),改变大视图的位置。它会给出一个外观和感觉,就像所有选中的按钮被拖动一样。此外,只要停止较大的视图拖动,就从主视图中删除所有原始选定的按钮。
希望它会对你有所帮助。