0
votes

I have some values of UIButtons. Every button I have created dynamically, by this code:

-(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 - is NSObject with string params of created buttons.

As you can see, I'm adding selector for every created button. I can move every button by this selector. Here is it's code:

- (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.
} 

Now I need to realize multi-select (select some value of buttons by tapping on them, to make some king of a group) and after that I need to move this group (all selected buttons) like one single object.

Any suggestions how to realize it?

2

2 Answers

0
votes

When the user select multiple buttons one by one , mark them all the selected buttons by changing their background image . Now when the user starts dragging any one of the selected button create all Bigger view (with the clear background color) and add the copies(new buttons look alike the selected buttons) of all the selected buttons and add them on to the bigger view . Now changing position of original button (button getting dragged) , change the position of bigger view . It will give a look and feel like all the selected button are getting dragged . Also as soon as the bigger view dragging is stopped remove all the original selected buttons from the main view .

Hope it will help you.

0
votes

you could set a different Tag to each buttons in AddNewTable like this:

[button setTag:];

and then in draggedOut you can find it by:

[sender tag]