ここにいる新しいプログラマーは、一歩一歩物事を進めようとしています。デバイスで現在触れている各場所の周りに円を描く方法を見つけようとしています。画面上の 2 本の指、各指の下に 1 つの円。
現在、1 つのタッチ位置に円を描く作業コードがありますが、画面に別の指を置くと、円はその 2 番目のタッチ位置に移動し、最初のタッチ位置は空のままになります。3分の1を追加すると、そこに移動します。
理想的には、各指に 1 つずつ、画面上に最大 5 つのアクティブな円を表示できるようにしたいと考えています。
これが私の現在のコードです。
@interface TapView ()
@property (nonatomic) BOOL touched;
@property (nonatomic) CGPoint firstTouch;
@property (nonatomic) CGPoint secondTouch;
@property (nonatomic) int tapCount;
@end
@implementation TapView
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[super touchesBegan:touches withEvent:event];
NSArray *twoTouch = [touches allObjects];
if(touches.count == 1)
{
self.tapCount = 1;
UITouch *tOne = [twoTouch objectAtIndex:0];
self.firstTouch = [tOne locationInView:[tOne view]];
self.touched = YES;
[self setNeedsDisplay];
}
if(touches.count > 1 && touches.count < 3)
{
self.tapCount = 2;
UITouch *tTwo = [twoTouch objectAtIndex:1];
self.secondTouch = [tTwo locationInView:[tTwo view]];
[self setNeedsDisplay];
}
}
-(void)drawRect:(CGRect)rect
{
if(self.touched && self.tapCount == 1)
{
[self drawTouchCircle:self.firstTouch :self.secondTouch];
}
}
-(void)drawTouchCircle:(CGPoint)firstTouch :(CGPoint)secondTouch
{
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextSetRGBStrokeColor(ctx,0.1,0.1,0.1,1.0);
CGContextSetLineWidth(ctx,10);
CGContextAddArc(ctx,self.firstTouch.x,self.firstTouch.y,30,0.0,M_PI*2,YES);
CGContextStrokePath(ctx);
}
appDelegate.mのメソッドでsetMultipleTouchEnabled:YES
宣言しました。didFinishLaunchingWithOptions
に基づいてdrawTouchCircle
を変更するメソッドでif ステートメントを使用しようとしましたが、すべてが壊れているようで、タッチした場所に円がありません。self.firstTouch.x
self.secondTouch.x
self.tapCount
私は自分の問題を見つけようとして非常に苦労しています.