Elias Rahme Elias Rahme - 1 year ago 222
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 Source
- (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)

@implementation UIView (Looks)
    // 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];

example usage (in this case on a web view

@property (strong) IBOutlet UIWebView *dossierBlock;
    [self _loadBookImage];

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

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

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download