Ios 手指松脱事件
我在Ios 手指松脱事件,ios,uikit,Ios,Uikit,我在情节提要中的UIViewcontroller上有5个图像。五幅图像中的四幅可以用手指在屏幕上移动(图1、2、3、4)。然后我创建了一个if语句:如果我将其中一个图像拖到固定的图像(最终图形)上,标签上会出现“text”。我在声明中写道。唯一的问题是标签上的文本在两个图像截获时立即出现。但是我想让它在用户移除手指“放下”图像时出现。我该怎么做 代码如下: //image movement -(void)touchesMoved:(NSSet *)touches withEvent:(UIEve
情节提要
中的UIViewcontroller
上有5个图像。五幅图像中的四幅可以用手指在屏幕上移动(图1、2、3、4)。然后我创建了一个if语句:如果我将其中一个图像拖到固定的图像(最终图形)上,标签上会出现“text”。我在声明中写道。唯一的问题是标签上的文本在两个图像截获时立即出现。但是我想让它在用户移除手指“放下”图像时出现。我该怎么做
代码如下:
//image movement
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
if ([touch view] == graph1) {
CGPoint location = [touch locationInView:self.view];
graph1.center = location;
[self interceptofgraphs];
}
if ([touch view] == graph2) {
CGPoint location = [touch locationInView:self.view];
graph2.center = location;
[self interceptofgraphs];
}
if ([touch view] == graph3) {
CGPoint location = [touch locationInView:self.view];
graph3.center = location;
[self interceptofgraphs];
}
if ([touch view] == graph4) {
CGPoint location = [touch locationInView:self.view];
graph4.center = location;
[self interceptofgraphs];
}
}
-(void)interceptofgraphs {
if (CGRectIntersectsRect(graph2.frame, finalgraph.frame))
graphlabel.text = [NSString stringWithFormat: @"Right answer. Well done!!"];
if (CGRectIntersectsRect(graph1.frame, finalgraph.frame))
graphlabel.text = [NSString stringWithFormat: @"Wrong!! not at all."];
if (CGRectIntersectsRect(graph3.frame, finalgraph.frame))
graphlabel.text = [NSString stringWithFormat: @"Wrong!! Try again"];
if (CGRectIntersectsRect(graph4.frame, finalgraph.frame))
graphlabel.text = [NSString stringWithFormat: @"Wrong!! NO"];
}
谢谢你们所有的回答 这应该有效:
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
//we'll almost certainly need a location of touch
CGPoint location = [touch locationInView:self.view];
//we store the reference of a view that was touched into touchedView
UIView *touchedView = [touch view];
//if view that was touched is one of the views we're interested in
if ((touchedView == graph1)||(touchedView == graph2)||
(touchedView == graph3)||(touchedView == graph4)) {
//we move it's center
//since the touchedView hold's a reference to the view that
//was touched - we're moving the right view for sure
touchedView.center = location;
}
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
//we only want to check whitch view was moved at the end
//when user releases the touch
[self interceptofgraphs];
}
这应该起作用:
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
//we'll almost certainly need a location of touch
CGPoint location = [touch locationInView:self.view];
//we store the reference of a view that was touched into touchedView
UIView *touchedView = [touch view];
//if view that was touched is one of the views we're interested in
if ((touchedView == graph1)||(touchedView == graph2)||
(touchedView == graph3)||(touchedView == graph4)) {
//we move it's center
//since the touchedView hold's a reference to the view that
//was touched - we're moving the right view for sure
touchedView.center = location;
}
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
//we only want to check whitch view was moved at the end
//when user releases the touch
[self interceptofgraphs];
}
重新标记;不是XCode问题。XCode只是IDE,这个问题与此无关;不是XCode问题。XCode只是IDE,这个问题与此无关。@Alessandro:添加了一些comments@Alessandro:添加了一些注释