我在UIViewcontroller
的{{1}}上有5张图片。可以用手指在屏幕上移动五个图像中的4个(图1,2,3,4)。然后我创建了一个if语句:如果我将其中一个图像拖到固定的图像上(最终图形),标签上会出现“文本”。在我的发言中,我写了拦截。唯一的问题是,一旦两个图像截取,标签上的文字就会出现。但我想让用户移开手指以“放下”图像时显示。我怎么能这样做?
以下是代码:
Storyboard
感谢所有回答!!
答案 0 :(得分:1)
这应该有效:
-(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];
}