0

我希望用户能够按下并拖动一个图像(例如:image1.png)并将其放在另一个图像上(例如:image2.png)。当用户释放时,第三个图像(例如:image3.png)被添加到屏幕上。我怎么能在 xcode 中做到这一点?

4

2 回答 2

1

做自己想做的事情没那么容易,你得开始看这个来自 Apple Developer program 的接触教程

于 2012-11-14T21:14:12.643 回答
0

这是图像移动的代码示例:

    -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
        UITouch *touch = [[event allTouches] anyObject];
        CGPoint location = [touch locationInView:self.view];
        if (CGRectContainsPoint([image1 frame], location)) {
        images.center = location;

        if (CGRectContainsPoint([image1 frame], [image2 frame]) {
           //place your code when image1 = images2       
           [self.view addSubview:image3];
           }
        }
    }

我认为这样的事情可以工作

于 2012-11-14T21:14:25.517 回答