touchesBegin &touchesMove Xcode Obj C 问题 [英] touchesBegin & touchesMove Xcode Obj C Question

查看:13
本文介绍了touchesBegin &touchesMove Xcode Obj C 问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以当您按下并拖动时,我的应用程序运行良好.我还在 Interface Builder 中将 UIButtons 设置为 Touch Down.

So I have my app working good when you press and drag along. I also have UIButtons set to Touch Down in Interface Builder.

当您拖动时,您需要从 UIButton 的外部拖动.您不能单击 UIButton 并拖动到另一个.

As well when you drag you need to drag from the outside of the UIButton. You cannot click on the UIButton and drag to the other.

触摸移动:

代码:

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {

UITouch *touch = [[event touchesForView:self.view] anyObject];
CGPoint location = [touch locationInView:touch.view];

if(CGRectContainsPoint(oneButton.frame, location))
{
    if (!oneButton.isHighlighted){
        [self oneFunction];
        [oneButton setHighlighted:YES];
    }
}else {
    [oneButton setHighlighted:NO];
}
//
if(CGRectContainsPoint(twoButton.frame, location)) 
{
    if (!twoButton.isHighlighted){
        [self twoFunction];
        [twoButton setHighlighted:YES];
    }
}else {
    [twoButton setHighlighted:NO];
}

}

开始接触:

代码:

- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 

   UITouch *touch = [[event touchesForView:self.view] anyObject];

CGPoint location = [touch locationInView:touch.view];

if(CGRectContainsPoint(oneButton.frame, location))
{
    [self oneFunction];
    [oneButton setHighlighted:YES];
}
if(CGRectContainsPoint(twoButton.frame, location))
{
    [self twoFunction];
    [twoButton setHighlighted:YES];
}

}

我希望能够点击任何按钮来触发功能&也可以从一个按钮拖动到另一个按钮并触发该功能.

I want to be able to click on any of the button fire the function & also be able to drag from one button on to the other and fire that function.

所以基本上只需点击一个按钮并将手指滑过并激活另一个按钮,而无需从按钮外部按下和滑动.

So basically just being able to click on a button and slide your finger over and activate the other button without having to press and slide from outside of the button.

我想我已经很接近了,需要一些帮助.希望这足够清楚.

I think I'm close, need a bit of help. Hope thats clear enough.

谢谢.

推荐答案

尝试了一些不同的东西.使用它效果更好:

Tried something different. Using this worked much better:

if(CGRectContainsPoint(myObject.frame, location) && lastButton != myObject) {

在 touchesBegan &touchesMoved.

Used it in touchesBegan & touchesMoved.

这篇关于touchesBegin &touchesMove Xcode Obj C 问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆