0

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

次に、複数選択 (ボタンをタップしていくつかの値を選択し、グループのキングを作成) を実現する必要があります。その後、このグループ (選択されたすべてのボタン) を 1 つのオブジェクトのように移動する必要があります。

それを実現する方法はありますか?

4

2 に答える 2

0

ユーザーが複数のボタンを 1 つずつ選択する場合は、背景イメージを変更して、選択したすべてのボタンをマークします。ユーザーが選択したボタンのいずれかをドラッグし始めると、すべての大きなビュー (クリアな背景色) を作成し、選択したすべてのボタンのコピー (新しいボタンは選択したボタンに似ています) を追加し、それらをより大きなビューに追加します。元のボタン(ボタンがドラッグされる)の位置を変更し、より大きなビューの位置を変更します。選択したすべてのボタンがドラッグされているようなルック アンド フィールが得られます。また、大きなビューのドラッグが停止するとすぐに、元の選択されたすべてのボタンをメイン ビューから削除します。

それがあなたを助けることを願っています。

于 2013-05-10T07:58:46.227 に答える
0

次のように、AddNewTable の各ボタンに異なるタグを設定できます。

[ボタン setTag:];

そして draggedOut では、次の方法で見つけることができます。

【差出人タグ】

于 2013-05-10T07:27:43.543 に答える