【发布时间】:2016-01-30 02:14:52
【问题描述】:
我一直在处理具有黑色和透明边的图像上的渐变矩形,我一直在寻找 react native 中的渐变对象,但我没有找到,但是有一个 react-native 模块这样做,但问题是它在 android 中的透明度确实有效,但在 iOS 中,它不起作用,它显示白色代替透明面
和我在寻找原生 iOS 解决方案相比,我做到了,但它有点复杂,我无法在 react native 中实现这个 sn-p
CAGradientLayer *gradientMask = [CAGradientLayer layer];
gradientMask.frame = self.imageView.bounds;
gradientMask.colors = @[(id)[UIColor whiteColor].CGColor,
(id)[UIColor clearColor].CGColor];
self.imageView.layer.mask = gradientMask; <-- // looking for a way to achieve this in react native
这是我的反应原生代码
<Image ref={r => this.image = r} style={styles.container} source={require('../assets/default_profile_picture.jpg')}>
<LinearGradient ref={r => this.gradiant = r} locations={[0, 1.0]} colors={['rgba(0,0,0,0.00)', 'rgba(0,0,0,0.80)']} style={styles.linearGradient}>
</LinearGradient>
</Image>
我不知道如何将LinearGradient 传递给Image 作为掩码
【问题讨论】:
-
实际上我遇到了一个在 iOS 中实现相同结果的工作区,我不得不编辑源代码
BVLinearGradient.m我用self.gradientLayer.colors = @[(id)[UIColor colorWithRed:0.0f/255.0f green:0.0f/255.0f blue:0.0f/255.0f alpha:0.80f].CGColor, (id)[UIColor clearColor].CGColor];覆盖了setColors的设置器
标签: android ios react-native