如何在iphone中点击按钮后获取触摸事件?
我的项目中有一个如何在iphone中点击按钮后获取触摸事件?,iphone,ios,objective-c,uiview,Iphone,Ios,Objective C,Uiview,我的项目中有一个ui按钮,单击按钮后,我在该按钮的顶部显示了一个ui视图,此时按钮仍处于隐藏状态。当我按住按钮并将手指移到重叠的ui视图上时,我想获得一个touchsmoved事件。据我所知,情况如下: -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{ UITouch *touch = [touches anyObject]; if ([touch view] == uiview) {
ui按钮
,单击按钮后,我在该按钮的顶部显示了一个ui视图
,此时按钮仍处于隐藏状态。当我按住按钮并将手指移到重叠的ui视图上时,我想获得一个touchsmoved
事件。据我所知,情况如下:
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch = [touches anyObject];
if ([touch view] == uiview)
{
NSLog(@"Touches moved");
}
但是当我按下按钮时,它不会被调用,当出现UIView
时,按钮被隐藏,当我松开按钮时,UIView被隐藏。有什么建议吗?您需要为重叠的UIView设置view.userInteractionEnabled=NO。
这将向按钮发送操作 您需要为重叠的UIView设置view.userInteractionEnabled=NO。
这将向按钮发送操作 您需要为重叠的UIView设置view.userInteractionEnabled=NO。
这将向按钮发送操作 您需要为重叠的UIView设置view.userInteractionEnabled=NO。
这将向按钮发送操作 我不明白你想做什么,但我建议你使用手势识别器,并在按钮上添加手势识别器
尝试使用此代码。我在自己开发的一款纸牌游戏中使用过这个。使用长按手势移动卡片。希望我能帮忙
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(addLongpressGesture:)];
[longPress setDelegate:self];
[YOUR_BUTTON addGestureRecognizer:longPress];
- (void)addLongpressGesture:(UILongPressGestureRecognizer *)sender {
UIView *view = sender.view;
CGPoint point = [sender locationInView:view.superview];
if (sender.state == UIGestureRecognizerStateBegan){
// GESTURE STATE BEGAN
}
else if (sender.state == UIGestureRecognizerStateChanged){
//GESTURE STATE CHANGED/ MOVED
CGPoint center = view.center;
center.x += point.x - _priorPoint.x;
center.y += point.y - _priorPoint.y;
view.center = center;
// This is how i drag my views
}
else if (sender.state == UIGestureRecognizerStateEnded){
//GESTURE ENDED
}
我不明白你想做什么,但我建议你使用手势识别器,并在按钮上添加手势识别器
尝试使用此代码。我在自己开发的一款纸牌游戏中使用过这个。使用长按手势移动卡片。希望我能帮忙
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(addLongpressGesture:)];
[longPress setDelegate:self];
[YOUR_BUTTON addGestureRecognizer:longPress];
- (void)addLongpressGesture:(UILongPressGestureRecognizer *)sender {
UIView *view = sender.view;
CGPoint point = [sender locationInView:view.superview];
if (sender.state == UIGestureRecognizerStateBegan){
// GESTURE STATE BEGAN
}
else if (sender.state == UIGestureRecognizerStateChanged){
//GESTURE STATE CHANGED/ MOVED
CGPoint center = view.center;
center.x += point.x - _priorPoint.x;
center.y += point.y - _priorPoint.y;
view.center = center;
// This is how i drag my views
}
else if (sender.state == UIGestureRecognizerStateEnded){
//GESTURE ENDED
}
我不明白你想做什么,但我建议你使用手势识别器,并在按钮上添加手势识别器
尝试使用此代码。我在自己开发的一款纸牌游戏中使用过这个。使用长按手势移动卡片。希望我能帮忙
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(addLongpressGesture:)];
[longPress setDelegate:self];
[YOUR_BUTTON addGestureRecognizer:longPress];
- (void)addLongpressGesture:(UILongPressGestureRecognizer *)sender {
UIView *view = sender.view;
CGPoint point = [sender locationInView:view.superview];
if (sender.state == UIGestureRecognizerStateBegan){
// GESTURE STATE BEGAN
}
else if (sender.state == UIGestureRecognizerStateChanged){
//GESTURE STATE CHANGED/ MOVED
CGPoint center = view.center;
center.x += point.x - _priorPoint.x;
center.y += point.y - _priorPoint.y;
view.center = center;
// This is how i drag my views
}
else if (sender.state == UIGestureRecognizerStateEnded){
//GESTURE ENDED
}
我不明白你想做什么,但我建议你使用手势识别器,并在按钮上添加手势识别器
尝试使用此代码。我在自己开发的一款纸牌游戏中使用过这个。使用长按手势移动卡片。希望我能帮忙
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(addLongpressGesture:)];
[longPress setDelegate:self];
[YOUR_BUTTON addGestureRecognizer:longPress];
- (void)addLongpressGesture:(UILongPressGestureRecognizer *)sender {
UIView *view = sender.view;
CGPoint point = [sender locationInView:view.superview];
if (sender.state == UIGestureRecognizerStateBegan){
// GESTURE STATE BEGAN
}
else if (sender.state == UIGestureRecognizerStateChanged){
//GESTURE STATE CHANGED/ MOVED
CGPoint center = view.center;
center.x += point.x - _priorPoint.x;
center.y += point.y - _priorPoint.y;
view.center = center;
// This is how i drag my views
}
else if (sender.state == UIGestureRecognizerStateEnded){
//GESTURE ENDED
}
你能展示一些代码如何打开这个视图并隐藏按钮吗?这会更容易。我在按钮顶部的xib中查看了uiview,并将其隐藏起来。当我点击按钮时,uiview将变为可见,当我松开按钮时,uiview将再次变为不可见。您能否展示一些代码,说明如何打开此视图并隐藏按钮?这会更容易。我在按钮顶部的xib中查看了uiview,并将其隐藏起来。当我点击按钮时,uiview将变为可见,当我松开按钮时,uiview将再次变为不可见。您能否展示一些代码,说明如何打开此视图并隐藏按钮?这会更容易。我在按钮顶部的xib中查看了uiview,并将其隐藏起来。当我点击按钮时,uiview将变为可见,当我松开按钮时,uiview将再次变为不可见。您能否展示一些代码,说明如何打开此视图并隐藏按钮?这会更容易。我在按钮顶部的xib中查看了uiview,并将其隐藏起来。当我点击按钮时,uiview变为可见,当我松开按钮时,uiview再次变为不可见。