在UIScrollView滚动时渐变UITextView

3
我有一个UIScrollView,其中包含通过编程方式创建的UIScrollViews包装的UIImageviews。 在主UIScrollView中,我有一个UITextView,该UITextView将根据滚动UIScrollView之间显示的图像视图而更改其内容。我想根据滚动UIScrollView的位置相应地降低正在显示的UITextView的alpha值。 例如,如果用户在从一个uiimageview到另一个uiimageview移动时滚动过程中已经完成了一半,则uitextview的alpha应为0.5。您有什么想法如何实现此结果?
1个回答

4
- (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

示例用法(在此情况下为 Web 视图)

@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)”。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接