2014-10-27 109 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」。