总而言之,当一张图片触及另一张图片时,我正试图获得结果。这不是我遇到的问题。当我点击它并拖动时,我无法让UIImageView移动。以下是我正在使用的代码!如果你能帮助我,请告诉我!谢谢!
·H
{
IBOutlet UIImageView *image1;
IBOutlet UIImageView *image2;
}
@property (nonatomic, retain) UIImageView *image1;
@property (nonatomic, retain) UIImageView *image2;
-(void)collision;
的.m
@synthesize image1, image2;
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch1 = [touches anyObject];
[self collision];
if ([touch1 view] != self.image1) {
return;
}
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch1 = [touches anyObject];
// If the touch was in the placardView, move the placardView to its location.
if ([touch1 view] == self.image1) {
CGPoint location = [touch1 locationInView:image1];
self.image1.center = location;
return;
}
}
-(void)collision
{
if (CGRectIntersectsRect(image1.frame, image2.frame)) {
NSLog(@"Touched");
}
}
**我能够让代码在我能够移动UIImageView的地方工作。
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch1 = [[event allTouches] anyObject];
image1.center = [touch1 locationInView:self.view];
return;
}
唯一的问题是,无论我在屏幕上触摸什么,图像都会移动到该位置。我怎么能在你必须触摸实际的UIImageView来移动它?谢谢!
答案 0 :(得分:1)
UIImageView默认userInteraction为false,因此你只需启用userInteraction为True即可 两个图像视图。