我正在尝试一个只有图片的应用。然后,当用户触摸图像时,会创建一个副本,然后将图像移动到另一个位置并将其放在那里。
这是我创建的代码:
-(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;
}
}
我的问题是我无法访问touchesBegan
中创建的*视图,并在touchesMoved
中使用它。是否有人知道公开这个图像视图?