gpt4 book ai didi

objective-c - touchesBegin & touchesMove Xcode Obj C 问题

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:57:56 27 4
gpt4 key购买 nike

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

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

触摸移动:

代码:

-(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];
}

我希望能够单击任何按钮来触发该功能,并且还能够从一个按钮拖动到另一个按钮并触发该功能。

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

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

谢谢。

最佳答案

尝试了一些不同的东西。使用这个效果更好:

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

在 touchesBegan 和 touchesMoved 中使用它。

关于objective-c - touchesBegin & touchesMove Xcode Obj C 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3050184/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com