1

Xcode で、iPhone の画面上の特定の場所に画像を表示するには、画像を表示したい場所をタッチすることで、どのようにすればよいでしょうか? 私が現在使用しようとしている方法は、ポイントの座標を取得してから、そのポイントに表示されるpngファイルを取得しようとすることです。これまでのコードは次のとおりです。

- (void) touchesBegan:(NSSet *)touches
            withEvent:(UIEvent *)event {
    UITouch *theTouch = [touches anyObject];
    startPoint = [theTouch locationInView:self.view];
    CGFloat x = startPoint.x;
    CGFloat y = startPoint.y;

しかし、ポイントを取得したので、そこに画像を表示する方法や、より効率的な方法があるかどうかはわかりません。何か案は?

4

2 に答える 2

0

After getting x,y coordinates of a touch event, set center point of your UIImageView to it.

UIImageView *myImage = ...

CGPoint myPoint = CGPointMake(x_touch, y_touch);

[myImage setCenter:myPoint]; 

you can also animate this change by using animate block on the image view like so:

    nsTimerInterval myAnimationDuration = 1.0;
    [UIView animateWithDuration:myAnimationDuration animations:^{
        [myImage setCenter:myPoint];

    }
    completion:^(BOOL finished){
        //handle completion tasks

    }];
于 2012-10-01T17:08:58.063 に答える
0

使用できます[-UIImage drawAtPoint:]

于 2012-10-01T03:45:53.850 に答える