2014-10-27 112 views
3

我有一个UIScrollView包含UIImageviews包装内部以编程方式创建的UIScrollViews。 在主UIScrollView里面我有一个UITextView,它将相应地改变它的内容到图像视图,同时在各种uiimageviews之间滚动。我想相应地将显示的UITextView的alpha减少到滚动的UIScrollView的位置。
例如如果用户在从一组uiimageviews移动到另一个视图的过程中进行滚动过程的一半,则uitextview的alpha值应为0.5。任何想法我怎么能达到这个结果?淡入淡出UITextView滚动uiscrollview

回答

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的+看起来

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