• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

ios - 向 iCarousel 项目添加自定义手势

[复制链接]
菜鸟教程小白 发表于 2022-12-12 21:50:24 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

您好
我已经使用 Xcode 有一段时间了,并且现在使用了很多次 UIGestureRecognizers。目前我正在开发一个需要轮播的 iPad 应用程序,所以有什么比使用 iCarousel 更好,因为我已经遇到过它,我认为它很棒。
我在向轮播项目添加 UISwipeGestureRecognizer 时遇到了一些问题(我会用它来删除“刷过”项目)。看起来很容易,但看起来 UIGestureRecognizer 不存在,但如果打印 view.recognizer 我可以看到它实际上存在。我错过了什么? 对于任何语言错误,我们深表歉意!

代码

- (UIView *)carouseliCarousel *)carousel viewForItemAtIndexNSUInteger)index reusingViewUIView *)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 actionselector(carouselSwipewipeHandler];
        //[swipeRecognizer setDirectionUISwipeGestureRecognizerDirectionUp)];
       // [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 actionselector(carouselSwipewipeHandler];
    [swipeRecognizer setDirectionUISwipeGestureRecognizerDirectionUp)];
    [view addGestureRecognizer:swipeRecognizer];

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


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

提前致谢!



Best Answer-推荐答案


默认情况下,任何时候只能激活一种手势,并且轮播在内部使用一种手势进行滚动。因此,如果您想使用其他手势,您需要为您的手势和轮播手势添加一个代理,以便您可以使它们工作 simultaneously .

关于ios - 向 iCarousel 项目添加自定义手势,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23315676/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap