1

私は iPhone アプリに取り組んでいます。そこから画像をドラッグして、テーブルビューの外UITableViewCell
にある別の場所にドロップする必要があります。UIView

(imageview は :[cell.contentView addSubview:imageView] として追加されました)。

これ、役立つヒント、サンプルコードについて教えてください?? UIImageView を UITableViewCell に追加しているため、タッチ イベント デリゲートがトリガーされません。

4

1 に答える 1

1

あまりイベントを取得しないUIImageViewので、次のようなものを使用UIButtonしてドラッグしてみてください。

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button addTarget:self action:@selector(imageTouch:withEvent:) forControlEvents:UIControlEventTouchDown];
[button addTarget:self action:@selector(imageMoved:withEvent:) forControlEvents:UIControlEventTouchDragInside];
[button setImage:[UIImage imageNamed:@"vehicle.png"] forState:UIControlStateNormal];
[self.view addSubview:button];

- (IBAction) imageMoved:(id) sender withEvent:(UIEvent *) event
{
    CGPoint point = [[[event allTouches] anyObject] locationInView:self.view];
    UIControl *control = sender;
    control.center = point;
}

中心点が他のメソッドと一致してUIButton を追加するUIView場合[UIView adSubview:]UIView

iOSの基本的なドラッグアンドドロップからこのコードを取得しました

見てみましょう : Superview の境界内で画像をドラッグする

于 2013-01-11T05:51:14.110 に答える