【问题标题】:How to set ICarousel to slide one time for one one image如何将ICarousel设置为一张一张图片滑动一次
【发布时间】:2012-05-17 15:23:11
【问题描述】:

我正在使用 ICarousel 制作我的电子相册。当您滑动相册时,ICarousel 的默认设置是它会移动一段距离。我需要的是只为一张图片滑动一次。我发现 ICarousel 不是基于 ScrollView 的,所以我不知道如何实现我的目的,有人知道吗?

【问题讨论】:

    标签: iphone ipad icarousel


    【解决方案1】:

    使用最新版本的 iCarousel 更新答案:

    iCarousel 现在通过设置支持单页滑动 pagingEnabled=YES。

    【讨论】:

      【解决方案2】:

      我建议关闭本机滚动并附加一个使用 scrollByNumberofItems 方法的 PanGestureRecognizer。

      [iCarousel setScrollEnabled:NO];
      

      然后在你的gestureRecognizer里面:

      [iCarousel scrollByNumberOfItems:1 duration:0.25];
      

      我自己试过了,效果很好。

      【讨论】:

      • 这段代码你在哪里写的? [iCarousel scrollByNumberOfItems:1 持续时间:0.25];
      • 您曾确定希望轮播在哪里滚动。对我来说,我把它放在 PanGestureRecognizer 里面。当手势被识别后,我用上面这行代码触发了轮播滚动。
      【解决方案3】:

      看来您必须使用由同一作者实现的另一个名为 SwipeView 的库。

      问题是在这里找到的。 https://github.com/nicklockwood/iCarousel/issues/247

      【讨论】:

        【解决方案4】:

        我通过设置实现了 iCarouselTypeCoverFlow 类型:

        //In ViewController.m
        self.carousel.pagingEnabled = YES;
        
        
        //In iCarousel.m change for smooth animation
        -(void)scrollByOffset:(CGFloat)offset duration:(NSTimeInterbal)duration{
            if (duration > 0.0)
            {
                _decelerating = NO;
                _scrolling = YES;
                _startTime = CACurrentMediaTime();
                _startOffset = _scrollOffset;
        //        _scrollDuration = duration;
        // set constant duration instead
                _scrollDuration = 1.0;
                _endOffset = _startOffset + offset;
                if (!_wrapEnabled)
                {
                    _endOffset = [self clampedOffset:_endOffset];
                }
                [_delegate carouselWillBeginScrollingAnimation:self];
                [self startAnimation];
            }
            else
            {
                self.scrollOffset += offset;
            }
        }
        

        【讨论】:

          【解决方案5】:

          修改 iCarousel 源代码 iCarousel.m 文件可以做到这一点!

          - (void)didPan:(UIPanGestureRecognizer *)panGesture {
          
           ......
          
               case UIGestureRecognizerStateChanged: {
                      CGFloat translation = _vertical? [panGesture translationInView:self].y: [panGesture translationInView:self].x;
          
                      translation = translation * 0.35; // Add This line to change the really translation.
          
                      ......
               }
          }
          

          那解决了我的问题,希望能帮到你!

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2015-07-26
            • 1970-01-01
            • 2019-08-05
            • 1970-01-01
            • 2022-01-19
            • 2012-03-09
            • 2023-01-16
            • 2012-11-09
            相关资源
            最近更新 更多