tvOS:didUpdateFocusInContext可防止点击次数

时间:2015-12-06 11:16:31

标签: ios objective-c tvos apple-tv

我的视图中有几个自定义按钮,并使用didUpdateFocusInContext制作了自定义焦点动画,我在视图中添加了UITapGestureRecognizer,当用户点击两次时,方法会运行!但问题是当didUpdateFocusInContext阻止双击操作直到focused context到达它的结尾(这意味着财富到最后一个按钮)时,方法将在没有可聚焦上下文时触发!怎么能防止这样的事情?这是我的代码:

- (void)didUpdateFocusInContext:(UIFocusUpdateContext *)context withAnimationCoordinator: (UIFocusAnimationCoordinator *)coordinator {


    //Setup focausing for main buttons
    for (UIButton *mainButton in _nextPrevButton){

        if (context.nextFocusedView == mainButton) {

            [UIView animateWithDuration:1 delay:0 usingSpringWithDamping:.40 initialSpringVelocity:.60 options:UIViewAnimationOptionAllowUserInteraction animations:^ {

                context.nextFocusedView.transform = CGAffineTransformMakeScale(1.2, 1.2);
                context.nextFocusedView.layer.shadowOffset = CGSizeMake(0, 0);
                context.nextFocusedView.layer.shadowOpacity = 1;
                context.nextFocusedView.layer.shadowRadius = 15;
                context.nextFocusedView.layer.shadowColor = [UIColor lightGrayColor].CGColor;
                context.nextFocusedView.layer.shadowOpacity = 1;

            } completion:nil];

        } else {

            [UIView animateWithDuration:1 delay:0 usingSpringWithDamping:.40 initialSpringVelocity:.60 options:UIViewAnimationOptionAllowUserInteraction animations:^ {
                context.previouslyFocusedView.transform = CGAffineTransformMakeScale(1, 1);
                context.previouslyFocusedView.layer.shadowOpacity = 0;
            } completion:nil];
        }
    }



if (context.nextFocusedView == _button1Focused) {   [self buttonFocused:context];   }   else if   (context.previouslyFocusedView == _button1Focused) {    [self buttonNotFocused:context];    }
if (context.nextFocusedView == _button2Focused) {   [self buttonFocused:context];   }   else if   (context.previouslyFocusedView == _button2Focused) {    [self buttonNotFocused:context];    }
if (context.nextFocusedView == _button3Focused) {   [self buttonFocused:context];   }   else if   (context.previouslyFocusedView == _button3Focused) {    [self buttonNotFocused:context];    }


}

攻丝方法:

- (void)viewDidLoad {
     UITapGestureRecognizer *rightTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleRightTap:)];
        [rightTap setAllowedPressTypes:@[@(UIPressTypeRightArrow)]];
        [rightTap setNumberOfTapsRequired:2];
        [self.view addGestureRecognizer:rightTap];
}

- (void)handleRightTap:(UITapGestureRecognizer *)sender {

  //or put the code here ! 

    if (sender.state == UIGestureRecognizerStateRecognized)
    {
        NSLog(@"Right Arrow");

    }
}

我尝试过其他州:

if (sender.state == UIGestureRecognizerStateBegan)
{
    // handling code
    NSLog(@"UIGestureRecognizerStateBegan ");
}


if (sender.state == UIGestureRecognizerStateEnded)
{
    // handling code
    NSLog(@" UIGestureRecognizerStateEnded ");
}

if (sender.state == UIGestureRecognizerStateRecognized)
{
    // handling code
    NSLog(@"UIGestureRecognizerStateRecognized");
}

但没有成功!

0 个答案:

没有答案