touchesBegin &touchesMove Xcode Obj C 问题

touchesBegin amp; touchesMove Xcode Obj C Question(touchesBegin amp;touchesMove Xcode Obj C 问题)
本文介绍了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 问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Why local notification is not firing for UNCalendarNotificationTrigger(为什么没有为UNCalendarNotificationTrigger触发本地通知)
iOS VoiceOver functionality changes with Bundle Identifier(IOS画外音功能随捆绑包标识符而变化)
tabbar middle tab out of tabbar corner(选项卡栏中间的选项卡角外)
Pushing UIViewController above UITabBar(将UIView控制器推送到UITabBar上方)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Get an event when UIBarButtonItem menu is displayed(显示UIBarButtonItem菜单时获取事件)