我有一个UIScrollView,其中包含封装在程序创建的UIScrollViews中的UIImageView。在主UIScrollView中,我有一个UITextView,当在各种uiimageview之间滚动时,它会根据显示的图像视图相应地更改其内容。我想将显示UITextView的alpha相应地减小到滚动UIScrollView的位置。
例如,如果用户在从一组uiimageview移动到另一组uiimagesview的同时滚动过程进行到一半,则uitextview的alpha应该是0.5。有什么想法吗?我该如何实现这个结果?
- (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+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
示例用法(在这种情况下,在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"。