如何处理点击过快的用户

Ano*_*ite 2 objective-c uiview uiviewanimationtransition xcode4

我有一个简单的viewController.View控制器使用动画.如果我正在显示列表,它将动画显示.那时它也会改变指向地图的按钮而不是指向列表.

因此,通过持续按下相同的按钮(实际上它是2个不同的按钮,但用户将其视为相同的按钮),用户可以保持从一个地图到另一个列表的切换,反之亦然.

工作良好.随着一些捕获.

如果用户点击太快怎么办?让我们说,鉴于我希望确实使用我的应用程序,罐装或惩罚它们不是一种选择.

这是目前的计划:

-(void) transitiontoViewController:(UIViewController *)toViewController duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL))completion1
{


    [self enableButtonWithBool:false];
    UIViewController * fromController = self.last2ViewsInTheContainer.lastObject;
    if (fromController.view.superview!= self.ContainerView)
    {
        return;
    }
    [self transitionFromViewController:fromController toViewController:toViewController duration:duration options:options animations:animations completion:^(BOOL finished) {
        if (completion1 == Nil) //can't execute nil block. can be more elegantly done with [completion1 invoke] if there is such function. Anyway, do nothing if completion1 is nil
        {

        }
        else
        {
            completion1 (finished);
        }
        [self.last2ViewsInTheContainer addObject:toViewController];

        if (self.last2ViewsInTheContainer.count>2)
        {
            [self.last2ViewsInTheContainer removeObjectAtIndex:0];
        }
    }];

    [self enableButtonWithBool:true];
    [self ReloadorRedraw];
}
Run Code Online (Sandbox Code Playgroud)

简单过渡.我只是想在功能结束时指出2个控制器视图具有相同的子视图.看起来函数结束时转换尚未完成.旧视图控制器并未真正删除等.

ReloadorRedraw的内容如下:

-(void)ReloadorRedraw;
{
    BGCRBadgerStandardViewViewController * listOrMap = nil;
    if ([self.last2ViewsInTheContainer lastObject]==self.filterController)
    {
        [self.changeFilterButton setBackgroundImage:[UIImage imageNamed:filterBarOpenImageString] forState:UIControlStateNormal];
        listOrMap = self.last2ViewsInTheContainer[0];
    }
    else
    {
        [self.changeFilterButton setBackgroundImage:[UIImage imageNamed:filterBarCloseImageString] forState:UIControlStateNormal];
        listOrMap = self.last2ViewsInTheContainer.lastObject;
    }

    if (listOrMap==self.listBusinessViewController)
    {
        self.navigationItem.rightBarButtonItem=self.mapButton;
    }
    else
    {
        self.navigationItem.rightBarButtonItem=self.listButton;
    }
}
Run Code Online (Sandbox Code Playgroud)

如果我点击太快,我收到了这条消息:不平衡调用开始/结束外观转换.对开始/结束外观转换的不平衡调用.

之后应用程序处于无效状态.

解决这种情况的一种方法是"禁用"按钮,直到动画结束.

-(void) transitiontoViewController:(UIViewController *)toViewController duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL))completion1
{


    [self enableButtonWithBool:false];
    UIViewController * fromController = self.last2ViewsInTheContainer.lastObject;
    if (fromController.view.superview!= self.ContainerView)
    {
        return;
    }
    [self transitionFromViewController:fromController toViewController:toViewController duration:duration options:options animations:animations completion:^(BOOL finished) {
        if (completion1 == Nil) //can't execute nil block. can be more elegantly done with [completion1 invoke] if there is such function. Anyway, do nothing if completion1 is nil
        {

        }
        else
        {
            completion1 (finished);
        }
        [self.last2ViewsInTheContainer addObject:toViewController];

        if (self.last2ViewsInTheContainer.count>2)
        {
            [self.last2ViewsInTheContainer removeObjectAtIndex:0];
        }

    [self enableButtonWithBool:true];
    [self ReloadorRedraw];
    }];

}
Run Code Online (Sandbox Code Playgroud)

基本上我在动

    [self enableButtonWithBool:true];
    [self ReloadorRedraw];
Run Code Online (Sandbox Code Playgroud)

到完成块.

函数enableButtonWithBool就是这个简单的函数:

-(void)enableButtonWithBool: (BOOL) enable
{
    self.mapButton.enabled=enable;
    self.listButton.enabled= enable;
    self.changeFilterButton.enabled =enable;
    self.searchBar.enabled =enable;
}
Run Code Online (Sandbox Code Playgroud)

这很好用.

我的伴侣不喜欢它.这是因为禁用按钮看起来很丑,即使只有0.3秒.用户不会喜欢它,即使这是为了他们自己的利益.

所以基本上我必须快速启用按钮,而不是等到应用程序结束.

但是如何做到这一点仍然可以构建一个能够承受用户快速点击的强大应用程序?

我认为如果有人能够解释何时完成"真正的"过渡,那将会有所帮助.我的意思是从旧的东西的superview实际删除并添加到subview新的东西.动画只是一部"电影",并没有真正改变过渡或视图结构吗?

jrt*_*ton 6

userInteractionEnabled在动画持续时间内将按钮设置为NO.这会禁用该按钮,但不会更改其外观或增加操作方法的复杂性.