【问题标题】:How can I stop views on screen from multiplying? (touchesBegan,touchesMoved,touchesEnded)如何阻止屏幕上的视图增加? (touchesBegan,touchesMoved,touchesEnded)
【发布时间】:2023-03-09 15:30:01
【问题描述】:

我是 Objective C 的新手,我正在尝试制作一个基本的益智游戏。我正在使用多个 UIImage 对象、一些标签和一个按钮。它包括将碎片移动到正确的位置。如果用户未能将一块棋子放在某个地方,则该棋子会回到原来的位置。

该部分运行良好,一旦我“删除”该视图并在其他屏幕上继续,问题就开始了。每当我点击屏幕上的任何地方时,视图都会无限增加。为什么会这样?

我该怎么办?,我太绝望了,我几乎尝试了所有方法,包括忽略触摸,阻止触摸等。这只会造成更多麻烦。

我已经尝试将使用交互设置为否,忽略交互事件,自动释放视图,但我没有找到解决方案。

任何帮助将不胜感激。问候!

--->我尝试发布图片,但鉴于我是新手,我无法发布,但如果需要,我可以将图片发送给任何人,以向您展示我得到的奇怪效果。

-(void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
    [self touchesCancelled:touches withEvent:event];
}

-(IBAction) navigationConversation: (id)sender{
    //[self.view.superview setUserInteractionEnabled:NO];
    //[[UIApplication sharedApplication] endIgnoringInteractionEvents];
    if (nextButton.hidden == NO) {
        conversation *navigationConversationController=[[conversation alloc]     initWithNibName:@"conversation" bundle:nil];
        [self.view addSubview:navigationConversationController.view];
        if (self.view.superview == nil)
            [navigationConversationController autorelease];
    }
    return;
}

【问题讨论】:

  • 只需发布该视图控制器的代码
  • 我上传了整个代码!希望它可以帮助澄清我的问题!

标签: iphone objective-c ipad-2 touchesbegan touchesmoved


【解决方案1】:

感谢上帝,问题现在解决了。这是我所做的更改,这纠正了错误。 :)

-(IBAction) navigationConversation: (id)sender{
    if (nextButton.hidden == NO) {
        //I disabled the interactions with the puzzle view in here, thus eliminating the problem
        [self.view.superview setUserInteractionEnabled:NO];
        conversation *navigationConversationController=[[conversation alloc]     initWithNibName:@"conversation" bundle:nil];
        [self.view addSubview:navigationConversationController.view];
        if (self.view.superview == nil)
            [navigationConversationController autorelease];
    }
    return;
}

感谢所有观看的人!并想帮忙!我希望这适用于其他有同样问题的人。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-01-29
    • 1970-01-01
    • 1970-01-01
    • 2011-03-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多