将自定义手势添加到iCarousel项目

时间:2014-04-26 19:42:26

标签: ios objective-c icarousel

嗨我已经和Xcode合作了一段时间,现在多次使用UIGestureRecognizers。此刻我正在开发一款需要旋转木马的iPad应用程序,所以比使用iCarousel更好,因为我已经遇到过它,我觉得它很棒。
我在向轮播项目添加UISwipeGestureRecognizer时遇到了一些问题(我会用它来删除"刷过"项目)。看起来很简单,但看起来UIGestureRecognizer不存在,但如果打印view.recognizer我可以看到它实际上存在。我错过了什么? 抱歉任何语言错误!

代码

- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view
{
    UILabel *nameLabel = nil;
    UILabel *notesLabel = nil;
    UIImageView *icon1 = nil;
    UIImageView *icon2 = nil;

    Notebook *referenceNotebook = [_notebookArray objectAtIndex:index];

    //create new view if no view is available for recycling
    if (view == nil)
    {
        view = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 250.0f, 373.0f)];
        ((UIImageView *)view).image = [UIImage imageNamed:@"notebookBase"];
        view.contentMode = UIViewContentModeCenter;

        CGPoint startingPoint = view.frame.origin;
        CGSize startingSize = view.frame.size;

        nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(startingPoint.x, startingPoint.y + 60, startingSize.width, 100)];
        nameLabel.backgroundColor = [UIColor clearColor];
        nameLabel.textAlignment = NSTextAlignmentCenter;
        nameLabel.font = [FontController useFontKlinic_Light:50];
        nameLabel.tag = 1;
        [view addSubview:nameLabel];

        notesLabel = [[UILabel alloc]initWithFrame:CGRectMake(startingPoint.x, startingPoint.y + 95, startingSize.width, 100)];
        notesLabel.backgroundColor = [UIColor clearColor];
        notesLabel.textAlignment = NSTextAlignmentCenter;
        notesLabel.font = [FontController useFontKlinic_Light:30];
        [view addSubview:notesLabel];

        icon1 = [[UIImageView alloc] initWithFrame:CGRectMake(startingPoint.x + 105, startingPoint.y + 18, 40, 40)];
        icon1.image = [UIImage imageNamed:@"notebookIcon1"];
        [view addSubview:icon1];

        icon2 = [[UIImageView alloc] initWithFrame:CGRectMake(startingPoint.x + 105, startingPoint.y + 320, 40, 40)];
        icon2.image = [UIImage imageNamed:@"notebookIcon1"];
        [view addSubview:icon2];

        //UIView *swipeView = [[UIView alloc] initWithFrame:CGRectMake(startingPoint.x, startingPoint.y, startingSize.width, startingSize.height)];
        //swipeView.backgroundColor = [UIColor clearColor];

        //UISwipeGestureRecognizer *swipeRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(carouselSwipewipeHandler:)];
        //[swipeRecognizer setDirection:(UISwipeGestureRecognizerDirectionUp)];
       // [swipeView addGestureRecognizer:swipeRecognizer];

        //[view addSubview:swipeView];
    }
    else
    {
        //get a reference to the label in the recycled view
        nameLabel = (UILabel *)[view viewWithTag:1];
    }

    nameLabel.text = referenceNotebook.name;
    notesLabel.text = @"n note";

    UISwipeGestureRecognizer *swipeRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(carouselSwipewipeHandler:)];
    [swipeRecognizer setDirection:(UISwipeGestureRecognizerDirectionUp)];
    [view addGestureRecognizer:swipeRecognizer];

    view.tag = index;
    NSLog(@"gesture recogs: %@", view.gestureRecognizers);
    return view;
}


任何人都知道我做错了什么? 这里还有 iCarousel文档的链接: https://github.com/nicklockwood/iCarousel#detecting-taps-on-item-views

提前致谢!

1 个答案:

答案 0 :(得分:1)

默认情况下,任何时候只能有一个手势处于活动状态,并且轮播在内部使用手势进行滚动。因此,如果您想使用其他手势,则需要为手势和轮播手势添加委托,以便您可以使其工作simultaneously