1

私は1つのアプリケーションを開発しています。私は1つのUIImageViewを使用しており、以下のコードを使用して0.5秒ごとにUIImageViewの位置を変更しています。

[NSTimer scheduledTimerWithTimeInterval:0.5
                                 target: self
                               selector:@selector(moveImage)
                               userInfo: nil repeats:YES];
-(void) moveImage
{
   //[image1 setCenter: CGPointMake(634, 126)];
   CGFloat x = (CGFloat) (arc4random() % (int) self.view.bounds.size.width);
   CGFloat y = (CGFloat) (arc4random() % (int) self.view.bounds.size.height);
   CGPoint squarePostion = CGPointMake(x, y);
   img.center=squarePostion;
} 

画面にタッチできるようになりました。私が知る必要があるのは、私のタッチ位置とそのイメージビューの位置の両方が正しいかどうかです。

4

2 に答える 2

2
use this 

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event

{

    UITouch *touch = [[event allTouches] anyObject];

    CGPoint touchLocation = [touch locationInView:self.view];

 if ([touch view] == photo1) {

        //photo1 is image view give tag to it
        if( photo1.tag==3)

        {
            NSLog(@"You have been touched image view");
        }



        photo1.center = touchLocation;

    }

}
于 2012-09-15T06:02:31.933 に答える
0
//it used to find the point in view
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{

    UITouch * touch = [touches anyObject];

    CGPoint pos = [touch locationInView: [UIApplication sharedApplication].keyWindow];
       NSLog(@"%f,%f",pos.x, pos.y);

}
于 2012-09-15T05:54:22.760 に答える