Elias Rahme Elias Rahme - 6 months ago 91
Objective-C Question

fade a UITextView while scrolling uiscrollview

I have a UIScrollView containing UIImageviews wrapped inside programmatically created UIScrollViews.
Inside that main UIScrollView i have a UITextView that will change it's content accordingly to the image view showing while scrolling between the various uiimageviews. I want to decrease the alpha of the showing UITextView accordingly to the position of the scrolled UIScrollView.

e.g. if the user is half way through the scrolling process while moving from one set of uiimageviews to another, the uitextview's alpha should be 0.5. Any Ideas how can i achieve this result ?

Answer
- (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
}

I just add logic how to approach.

Or you can use a category. Make a category on UIView called 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

example usage (in this case on a web view

@property (strong) IBOutlet UIWebView *dossierBlock;
-(void)_fillMainArea
    {
    [self _loadBookImage];

    NSString *longHtml = CLOUD.caMeeting[@"yourJsonTag"];
    nullsafe(longHtml);

    [self.dossierBlock longHtml baseURL:nil];
    [self.dossierBlock fadeTail];
    }

You can trivially make a "fadeTop" in the same way.