1

我正在尝试做一个只有图像的应用程序。然后,当用户触摸图像时,会创建一个副本,然后可以将图像移动到另一个位置并将其放在那里。

这是我创建的代码:

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

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

CGPoint touch_point = [myTouch locationInView:view1];

    if ([view1 pointInside:touch_point withEvent:event]) {
        UIImageView *view= [UIImageView alloc];
        [self.view addSubview:view];
        [view release];
        view.userInteractionEnabled=YES;
        view.frame = CGRectMake(0, 0, 100.0, 100.0);
        view.center = [myTouch locationInView:self.view];
    }       

}

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

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

    CGPoint touch_point = [myTouch locationInView:view1];

    if ([view1 pointInside:touch_point withEvent:event]) {
        view.image=view1.image;
    }

}

我的问题是我无法访问在 中创建的 *viewtouchesBegan并在touchesMoved. 有人知道如何公开此图像视图吗?

4

0 回答 0