2

写真の上にボックスの形を重ねて、ユーザーが各コーナーを選択できるようにし、コーナーを目的の場所にドラッグしたいと思います。

ドラッグイベントに応答して各コーナーのx、yポイントを取得する4つの非表示ボタン(各コーナーを表す)を使用できますが、ゲームAPIクラスに触れることなくxcodeで利用できる線画機能はありますか?UIViewに線を引きたいと思います。

どうもありがとう、-コード

4

1 に答える 1

2

ビューを表すサブクラスを作成UIViewします。ビューに a を追加UIImageViewします。これにより、ユーザーの描画で画像が保持されます。

UIViewサブクラスでのユーザー操作を有効にします。

self.userInteractionEnabled = YES;

サブクラスにこのメソッドを実装して、開始タップを検出します。

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    // We are starting to draw
    // Get the current touch.
    UITouch *touch = [touches anyObject];    
    startingPoint = [touch locationInView:self];
}

直線を描くための最後のタップを検出します。

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [touches anyObject];    
    endingPoint = [touch locationInView:self];

    // Now draw the line and save to your image
    UIGraphicsBeginImageContext(self.frame.size);

    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetLineWidth(context, 10);
    CGContextMoveToPoint(context, NULL, startingPoint.x, startingPoint.y);
    CGContextAddLineToPoint(context, NULL, endingPoint.x, endingPoint.y);
    CGContextSetRGBFillColor(context, 255, 255, 255, 1);
    CGContextSetRGBStrokeColor(context, 255, 255, 255, 1);
    CGContextStrokePath(context);
    self.image = UIGraphicsGetImageFromCurrentImageContext();
    CGContextRelease(context);
}
于 2012-07-26T09:54:47.207 に答える