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


基础教程推荐
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01