向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-点击项目视图

提前感谢!

默认情况下,任何时候都只能激活一个手势,转盘在内部使用一个手势进行滚动。因此,如果你想使用其他手势,你需要在你的手势和旋转木马手势中添加一个代理,这样你就可以让它们同时工作。

最新更新