【问题标题】:How to fade all items before currentItem with iCarousel?如何使用 iCarousel 淡化 currentItem 之前的所有项目?
【发布时间】:2014-11-13 23:32:05
【问题描述】:

我正在使用带有自定义转换的 iCarousel 插件,并尝试制作特定的淡入淡出效果。 我希望当前项目之前的所有项目都褪色,但当前项目和所有项目都没有褪色。有没有办法使用淡入淡出选项来做到这一点?我试过但没有成功。 所以我尝试在旋转木马的视图上制作动画。 这就是我在这里得到的:

- (void)carouselCurrentItemIndexDidChange:(iCarousel *)carousel
{
    UIView *viewToFadeOut = [carousel itemViewAtIndex:self.carousel.currentItemIndex-1];
    [UIView animateWithDuration:0.5 delay:0.0 options:0 animations:^{
        viewToFadeOut.alpha = 0.6f;
    } completion:^(BOOL finished) {

    }];

    UIView *viewToFadeIn = [carousel itemViewAtIndex:self.carousel.currentItemIndex];
    [UIView animateWithDuration:0.5 delay:0.0 options:0 animations:^{
        viewToFadeIn.alpha = 1.0f;
    } completion:^(BOOL finished) {

    }];
}

但它并不能完全按照我的意愿工作,因为一旦当前项目更改,fadeIn 动画就会开始,所以动画开始太晚了。

也许有办法实现类似的方法

- (void)carouselCurrentItemIndexWillChange:(iCarousel *)carousel;

并延迟开始淡出动画?

【问题讨论】:

    标签: ios objective-c xcode icarousel


    【解决方案1】:

    如果我理解正确,您只需将其添加到您的委托:

    - (CGFloat)carousel:(iCarousel *)carousel valueForOption:(iCarouselOption)option withDefault:(CGFloat)value
    {
        if (option == iCarouselOptionFadeMin)
        {
            return 0.0;
        }
        else if (option == iCarouselOptionFadeMinAlpha)
        {
            return 0.6;
        }
        return value;
    }
    

    【讨论】:

    • 谢谢其实真的很容易......我猜没有成功阅读。非常感谢它的魅力
    • @NicossB 还有一种方法可以淡出所有项目,除了中心项目以外的线性模式?
    • @Mr.Bean 这就是这段代码的作用。使用什么模式并不重要。
    【解决方案2】:

    使用 Swift 3(如果您在使 iCarousel 与 Swift 3 一起工作时遇到问题,请查看 https://medium.com/@arb1nsnmgl/icarousel-walkthrough-swift-3-0-887554155242#.bgs3r7n7b

    func carousel(_ carousel: iCarousel, valueFor option: iCarouselOption, withDefault value: CGFloat) -> CGFloat {
        if (option == .fadeMin)
        {
            return 0;
        } else if (option == .fadeMinAlpha)
        {
            return 0.3;
        } else if (option == .fadeMax)
        {
            return 0.3;
        }
        return value;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-02-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-13
      • 1970-01-01
      • 1970-01-01
      • 2016-12-08
      相关资源
      最近更新 更多