写真の上にボックスの形を重ねて、ユーザーが各コーナーを選択できるようにし、コーナーを目的の場所にドラッグしたいと思います。
ドラッグイベントに応答して各コーナーのx、yポイントを取得する4つの非表示ボタン(各コーナーを表す)を使用できますが、ゲームAPIクラスに触れることなくxcodeで利用できる線画機能はありますか?UIViewに線を引きたいと思います。
どうもありがとう、-コード
写真の上にボックスの形を重ねて、ユーザーが各コーナーを選択できるようにし、コーナーを目的の場所にドラッグしたいと思います。
ドラッグイベントに応答して各コーナーのx、yポイントを取得する4つの非表示ボタン(各コーナーを表す)を使用できますが、ゲームAPIクラスに触れることなくxcodeで利用できる線画機能はありますか?UIViewに線を引きたいと思います。
どうもありがとう、-コード
ビューを表すサブクラスを作成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);
}