Fade UITextView on scrolling uiscrollview

I have a UIScrollView containing UIImageviews wrapped inside programmatically generated UIScrollViews. Inside this main UIScrollView, I have a UITextView that will change its content to match the image view as it scrolls between different uiimageviews. I want to reduce the alpha of the UITextView display to match the position of the scrolled UIScrollView. for example, if the user is halfway through the scrolling process, moving from one set of uiimageviews to another, the alpha version of uitextview should be 0.5. Any ideas how I can achieve this result?

+3


source to share


1 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'm just adding logic on how to approach.

Or you can use a category. Create a category in UIView called UIView + Looks

@interface UIView (Looks)
-(void)fadeTail;
@end

@implementation UIView (Looks)
-(void)fadeTail
    {
    // it 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 of use (in this case the web page

@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 do "fadeTop" in the same way.

+4


source







All Articles