【问题标题】:How do I add a Touch Event to this UIScrollView Infinite Scroll Picker?如何向此 UIScrollView Infinite Scroll Picker 添加触摸事件?
【发布时间】:2014-02-24 15:11:17
【问题描述】:

我在我的项目中使用来自 GitHub https://github.com/Seitk/InfiniteScrollPicker/ 的 InfiniteScrollPicker。它现在的工作方式是当滚动菜单停止选择时,它会自动加载情节提要场景。我想更改它,以便您必须点击菜单图像才能加载情节提要场景,而不是在选择时发生。我该怎么做?

我认为这是我需要更改的 InfiniteScrollPicker.m 中的相关代码。我想我会用某种手势识别器来做,但我不确定在哪里或如何将它添加到下面的代码中。

    // Disable scrolling when snapping to new location
    dispatch_queue_t queue = dispatch_get_main_queue();
    dispatch_async(queue, ^ {
        [self setScrollEnabled:NO];
        [self scrollRectToVisible:CGRectMake(newX, 0, self.frame.size.width, 1) animated:YES];

        dispatch_async(dispatch_get_main_queue(), ^ {

            SEL selector = @selector(infiniteScrollPicker:didSelectAtImage:);
            if ([[self firstAvailableUIViewController] respondsToSelector:selector])
            {
                #pragma clang diagnostic push
                #pragma clang diagnostic ignored "-Warc-performSelector-leaks"
                [[self firstAvailableUIViewController] performSelector:selector withObject:self withObject:biggestView.image];
                #pragma clang diagnostic pop
            }

            [self setScrollEnabled:YES];
            snapping = 0;
        });

这是我的 ViewController.m 中相应代码的一部分

- (void)infiniteScrollPicker:(InfiniteScrollPicker *)infiniteScrollPicker didSelectAtImage:(UIImage *)buttonIndex
{    
    if (buttonIndex == [UIImage imageNamed:@"menu_0.png"]) {

        NSLog(@"First Menu Item Selected");
        UIStoryboard *playGame = [UIStoryboard storyboardWithName:@"Storyboard_iPhone" bundle:nil];
        UIViewController *playGameVC = [gameOver instantiateViewControllerWithIdentifier:@"PlayGame1"];
        [self presentModalViewController:playGameVC animated:YES];

    }
    if (buttonIndex == [UIImage imageNamed:@"menu_1.png"]) {
        NSLog(@"Second Menu Item Selected");
        UIStoryboard *playGame = [UIStoryboard storyboardWithName:@"Storyboard_iPhone" bundle:nil];
        UIViewController *playGameVC = [gameOver instantiateViewControllerWithIdentifier:@"GameOverScene"];
        [self presentModalViewController:gameOverVC animated:YES];

感谢您的帮助!

【问题讨论】:

    标签: ios uiviewcontroller uiscrollview uistoryboard


    【解决方案1】:

    你应该看看UITapGestureRecognizer,它是用来识别水龙头的。这是文档:https://developer.apple.com/library/ios/documentation/uikit/reference/UITapGestureRecognizer_Class/Reference/Reference.html

    【讨论】:

    • 我已经看过了。这就是我提到手势识别器的原因。该链接对当前代码没有帮助,因为我不确定在哪里更改当前代码。我试过的东西没有用。
    • 我只是尝试在SEL Selector 行上方添加此内容,并在if 语句内部添加,但两个选项均无效。 UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapDetected:)]; tapRecognizer.numberOfTapsRequired = 1;
    猜你喜欢
    • 2011-06-07
    • 2018-05-18
    • 1970-01-01
    • 2011-02-27
    • 2011-07-10
    • 2018-01-19
    • 1970-01-01
    • 2020-02-08
    • 1970-01-01
    相关资源
    最近更新 更多