gpt4 book ai didi

ios - 手指松开事件

转载 作者:行者123 更新时间:2023-11-29 13:38:53 25 4
gpt4 key购买 nike

我在 Storyboard 中的 UIViewcontroller 上有 5 张图片。可以用手指在屏幕上移动五幅图像中的四幅(图 1、2、3、4)。然后我创建了一个 if 语句:如果我将其中一个图像拖到固定图像(最终图形)上,标签上会出现“文本”。在我的声明中,我写了拦截。唯一的问题是标签上的文本在两个图像截断后立即出现。但我想让它在用户移开手指“放下”图像时出现。我该怎么做?

代码如下:

//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];
}

关于ios - 手指松开事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9743015/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com