- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 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/
我用 cocos2d 制作了我的第一个应用程序,所以我在这里很新 我的第一个问题: 我不会让物体(船)跟随我的手指。 -(void) ccTouchMoved:(UITouch *)touch wit
如果某人将右手压在扫描仪的玻璃上进行扫描,结果将如下所示: (没有橙色和白色注释)。我们如何确定某人的 2D:4D ratio从他们的手的图像? 最佳答案 您已经标记了这个很棒的 opencv - 我
我的 View Controller 中有几个 UIScrollView。我想覆盖一个通过 UIPanGestureRecognizer 捕获 2 根手指滑动的 View ,它不会记录 UIScrol
现在这真是令人困惑...在不离开页面的情况下更新 mysql 数据库...我有 3 位代码。 head 标签中的 javascript、body 中的操作按钮以及要在另一个页面上执行的代码。以下是三个
我有这段代码是从 Style clipboard in flutter 得到的 showMenu( context: context, // TODO: Positio
我是一名优秀的程序员,十分优秀!