【问题标题】:fade a UITextView while scrolling uiscrollview滚动 uiscrollview 时淡化 UITextView
【发布时间】:2014-10-27 10:34:41
【问题描述】:

我有一个 UIScrollView,其中包含包装在以编程方式创建的 UIScrollView 中的 UIImageview。 在那个主要的 UIScrollView 里面我有一个 UITextView,它会根据在各种 uiimageviews 之间滚动时显示的图像视图来改变它的内容。我想根据滚动的 UIScrollView 的位置减少显示 UITextView 的 alpha。
例如如果用户在从一组 uiimageview 移动到另一组时处于滚动过程的一半,则 uitextview 的 alpha 应为 0.5。任何想法我怎样才能达到这个结果?

【问题讨论】:

    标签: ios objective-c iphone uiscrollview


    【解决方案1】:
    - (void)scrollViewDidScroll:(UIScrollView *)scrollView
    {
     CGFloat offset = scrollView.contentOffset.x; // here you will get the offset value
     CGFloat value = offset / totalcontentsize;
     // use 'value' for setting the textview alpha value
    }
    

    我只是添加逻辑如何处理。

    或者您可以使用类别。在 UIView 上创建一个名为 UIView+Looks 的类别

    @interface UIView (Looks)
    -(void)fadeTail;
    @end
    
    @implementation UIView (Looks)
    -(void)fadeTail
        {
        // it's used to fade away the bottom,
        // perhaps of a slab of text, web view or similar
    
        CAGradientLayer *gradient = [CAGradientLayer layer];
        gradient.frame = self.bounds;
        gradient.colors = @[
            (id)[[UIColor whiteColor] CGColor],
            (id)[[UIColor clearColor] CGColor]
            ];
        gradient.startPoint = CGPointMake(0.5, 0.93);
        gradient.endPoint = CGPointMake(0.5, 1);
    
        [self.layer setMask:gradient];
        }
    @end
    

    示例用法(在本例中为网络视图

    @property (strong) IBOutlet UIWebView *dossierBlock;
    -(void)_fillMainArea
        {
        [self _loadBookImage];
    
        NSString *longHtml = CLOUD.caMeeting[@"yourJsonTag"];
        nullsafe(longHtml);
    
        [self.dossierBlock longHtml baseURL:nil];
        [self.dossierBlock fadeTail];
        }
    

    你可以用同样的方法简单地制作一个“fadeTop”。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-08-23
      • 1970-01-01
      • 2011-03-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多