0

画面上で指を動かしているときに、ビュー全体に画像を追加する際に問題が発生しています。

現在、画像を複数回追加していますが、それらを近づけすぎて、実際には私のタッチに従っていません。

編集:

私が欲しいもの:

画像を取得または選択した後、ユーザーはリストから別の画像を選択できます。ユーザーがタッチしてビュー全体で指を動かすと、選択した画像が、それぞれの場所で重なることなく指をドラッグした場所に表示されます。

これは機能します:

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
     UITouch *touch = [touches anyObject];
     currentTouch = [touch locationInView:self.view];

     CGRect myImageRect = CGRectMake(currentTouch.x, currentTouch.y, 80.0f, 80.0f);
     myImage = [[UIImageView alloc] initWithFrame:myImageRect];
     [myImage setImage:[UIImage imageNamed:@"dot.png"]];
     [self.view addSubview:myImage];
     [myImage release];
}

新しい質問: ビューに画像を描画するときに画像がきつくならないように、これにスペースを追加するにはどうすればよいですか?

4

3 に答える 3

0

画面をスワイプしながら、touchesMovedメソッドの代わりにUISwipeGestureRecognizerを以下のように使用することもできます。viewDidload:method、

UISwipeGestureRecognizer *swipeup = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipedone:)];
swipeup.direction = UISwipeGestureRecognizerDirectionUp;
swipeup.numberOfTouchesRequired=1;
[self.view addGestureRecognizer:swipeup];

メソッド定義:

-(IBAction)swipedone:(UISwipeGestureRecognizer*)recognizer
{
    NSLog(@"swiped");
    UIImageView* _aImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"1.png"]];
    _aImageView.frame = CGRectMake(10, 10, 100, 100);
    _aImageView.multipleTouchEnabled = YES;
    _aImageView.userInteractionEnabled = YES;
    CGPoint point = [recognizer locationInView:recognizer.view];
    [_aImageView setFrame:CGRectMake(point.x, point.y, 80.0, 80.0)];
    [self.view addSubview:_aImageView];
    [_aImageView release];
}

現在、このコードを上にスワイプするために使用しています。うまくいくと思います。一度試してみてください。

于 2012-11-06T06:45:32.677 に答える
0

あなたはあなたの質問をもっと説明したいかもしれません.あなたは正確に何を達成しようとしています! 画像をオーバーラップさせたくない場合は、これを試すことができます!

UITouch * touch = [touches anyObject];
touchPoint = [touch locationInView:imageView];
prev_touchPoint = [touch previousLocationInView:imageView];

if (ABS(touchPoint.x - prev_touchPoint.x) > 80 
    || ABS(touchPoint.y - prev_touchPoint.y) > 80) {

   _aImageView = [[UIImageView alloc] initWithImage:aImage];
   _aImageView.multipleTouchEnabled = YES;
   _aImageView.userInteractionEnabled = YES;
  [_aImageView setFrame:CGRectMake(touchPoint.x, touchPoint.y, 80.0, 80.0)];
  [imageView addSubview:_aImageView];
  [_aImageView release];
}
于 2012-11-06T04:15:23.263 に答える
0

私は会社にいて、あまりにも大きなデータ (コード) を投稿できないため、申し訳ありません。圧迫は、最後のタッチポイントとのタッチポイントの距離を確認していないためです。ポイントがビュー内にあるかどうかを確認します。bool CGRectContainsPoint (CGRect rect,CGPoint point);つまり、 のタッチ ポイントを覚えているということtouchesBegan:です。touchesMomved:新しいタッチインが画像の幅または左よりも大きい場合は更新します。そして add image ビューをメソッドに入れて use と呼びます- (void)performSelectorInBackground:(SEL)aSelector withObject:(id)arg

于 2012-11-06T04:57:26.520 に答える