在 UIView 转换时点击按钮,翻转或翻转 [英] Hitting buttons while UIView is in transition, flipping in or out

查看:20
本文介绍了在 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];

在翻转过渡中涉及的两个视图上,然后

on both the views involved in the flip transition, and then

[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天全站免登陆