在UIView处于转换状态时按下按钮,向内或向外翻转 [英] Hitting buttons while UIView is in transition, flipping in or out

查看:109
本文介绍了在UIView处于转换状态时按下按钮,向内或向外翻转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的儿子刚刚发现他可以点击我的视图的完成按钮,翻转到上一个视图,一次开始翻转,一次或多次视图处于转换状态(翻转)。第二次和下一次点击将再次触发相同的操作,创建一些有趣的结果,例如最终没有可见的视图,但是我的底层UIWindow。

My son just discovered that he could hit my view's "Done" button, which flips to the previous view, once to start the flip and one or more times as the view is in transition (flipping out). The second and next hits would trigger the same action over again, creating some interesting results, such as ending up with no views visible, but my underlying UIWindow.

我在想我应该致电:

[coming.view setUserInteractionEnabled: NO];
[going.view setUserInteractionEnabled: NO];

然后

[coming.view setUserInteractionEnabled: YES];

动画结束后的最终视图。

on the final view after animation has ended.

我在想,在任何视图都处于转换状态时,可能会有一些全局禁用点击的方法。你怎么看?

I was thinking that maybe better than this would be some way to globally disable taps while any view was in transition. What do you think?

以下是整个视图切换代码:

Here is the entire view switching code:

- (void)switchTwoViews:(UIViewController *)view1 otherView:(UIViewController *)view2
{
    /*
     This method is called to switch views.
     It flips the displayed view from the main view to the flipside view and vice-versa.
     */

    UIViewController *coming = nil;
    UIViewController *going = nil;
    UIViewAnimationTransition transition;

    [view1.view setUserInteractionEnabled: NO];
    [view2.view setUserInteractionEnabled: NO];
    if (view1.view.superview == nil) {
        coming = view1;
        going = view2;
        transition = UIViewAnimationTransitionFlipFromLeft;
    }
    else {
        coming = view2;
        going = view1;
        transition = UIViewAnimationTransitionFlipFromRight;
    }
    //  coming.view.frame = [UIScreen mainScreen].applicationFrame;

    //  going.view.alpha = 1.0;     //uncomment these lines if we want fading of views
    //  coming.view.alpha = 0.0;

    NSArray *viewArray = [[NSArray alloc] initWithObjects:coming, going, nil];
    [coming viewWillAppear:YES];
    [going viewWillDisappear:YES];
    [UIView beginAnimations:@"View Flip" context:viewArray]; {
        [UIView setAnimationDuration:1.0];
        [UIView setAnimationDelegate:self];
        [UIView setAnimationDidStopSelector:@selector(animationDidEnd:finished:context:)];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

        //      coming.view.alpha = 1.0;        //uncomment these lines if we want fading of views
        //      going.view.alpha = 0.0;

        [UIView setAnimationTransition:transition forView:self.view cache:YES];
        [self.view addSubview: coming.view];
    }
    [UIView commitAnimations];

}

- (void) animationDidEnd:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context
{
    NSArray *viewArray = context;
    [((UIViewController *)[viewArray objectAtIndex:1]).view removeFromSuperview];
    [[viewArray objectAtIndex:1] viewDidDisappear:YES];
    [[viewArray objectAtIndex:0] viewDidAppear:YES];
    [[[viewArray objectAtIndex:0] view] setUserInteractionEnabled: YES];
    [viewArray release];
}


推荐答案

setUserInteractionEnabled:似乎是要走的路。有异议吗?

setUserInteractionEnabled: seems to be the way to go. Any objections?

这篇关于在UIView处于转换状态时按下按钮,向内或向外翻转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆