Удаление childViewController в iOS

Я добавляю ChildViewController таким образом, который открывает половину экрана.

   m_customStartupView = [[CustomStartUpViewController alloc]init];
        m_customStartupView.delegate = self;

        if(m_showStatus == SHOW_STATUS)
        {
             m_customStartupView.dialogToShow = LAST_SYNC_STATUS;
        }       


        [self addChildViewController:m_customStartupView];
        [[self view] addSubview:[m_customStartupView view]];
        [m_customStartupView didMoveToParentViewController:self];


        CGRect rect = m_customStartupView.view.frame;
        if(IPHONE_5)
        {
            rect.origin.y = 568;
        }

        else
        {
            rect.origin.y = 480;
        }

        m_customStartupView.view.frame = rect;

        [UIView beginAnimations:@"ShowView" context:nil];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
        [UIView setAnimationDuration:0.2];
        if(IPHONE_5)
        {       
            rect.origin.y = 520;
        }
        else
        {
            rect.origin.y = 420;
        }

        m_customStartupView.view.frame = rect;
        [UIView commitAnimations];

При увольнении ChildView я звоню это:

-(void)dismissStartupAlertView:(BOOL)buttonClicked
{   
    CGRect rect = m_customStartupView.view.frame;
    if(IPHONE_5)
    {
        rect.origin.y =  520
    }
    else
    {
        rect.origin.y = 420 
    }
    m_customStartupView.view.frame = rect;

    [UIView beginAnimations:@"ShowView" context:nil];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationDuration:0.2];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
    if(IPHONE_5)
    {
        rect.origin.y = 568;
    }
    else
    {
        rect.origin.y = 480;
    }

    m_customStartupView.view.frame = rect;
    [UIView commitAnimations];
}


- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context
{
    if([animationID isEqualToString:@"ShowView"])
    {
        [m_customStartupView willMoveToParentViewController:nil];
        [m_customStartupView.view removeFromSuperview];
        [m_customStartupView removeFromParentViewController];
    }
}

Таким образом, у меня есть две кнопки, Кнопка 1 и Кнопка 2, когда пользователь нажимает кнопку 1, дочерний вид анимируется снизу и показывает. Теперь, если пользователь нажимает кнопку 2, предыдущий childView отклоняется, а затем отображается новый childView.

Таким образом, проблема в том, что, если я нажимаю обе кнопки очень быстро, как при игре в казино, дочерние элементы перекрываются.

1) Как мы можем решить эту проблему.

2) правильно ли я делаю

С уважением, Ранджит

1 ответ

Попробуйте временно отключить кнопку 2 во время анимации:

   [button2 setEnabled:NO]

Затем измените это, когда анимация закончится:

  [button2 setEnabled:YES]
Другие вопросы по тегам