Luc*_*igh 13 android image ios react-native
我想知道为什么我的图像不显示。我想要的是我的图像在背景中,底部有两个按钮,在图像上方。我正在使用本机反应,以及用于应用程序的 IDE 'Deco'。现在根本没有图像显示:
import React, { Component } from 'react';
import { Button,Alert, TouchableOpacity,Image, Dimensions } from 'react-native'
import {
AppRegistry,
StyleSheet,
Text,
View,
} from 'react-native';
class Project extends Component {
render() {
return (
<View style={{backgroundColor: '#375D81', flex: 1}}>
<Image source={{uri: 'https://upload.wikimedia.org/wikipedia/commons/f/f0/Everest_North_Face_toward_Base_Camp_Tibet_Luca_Galuzzi_2006_edit_1.jpg'}}/>
<View style = {styles.container}>
<TouchableOpacity style = {styles.buttonText1} onPress={() => { Alert.alert('You tapped the button!')}}>
<Text style={styles.text}>
Button 1
</Text>
</TouchableOpacity>
<TouchableOpacity style = {styles.buttonText2} onPress={() => { Alert.alert('You tapped the button!')}}>
<Text style= {styles.text}>
Button 2
</Text>
</TouchableOpacity>
</View>
</View>
);
}
}
const styles = StyleSheet.create({
main: {
backgroundColor: 'blue'
},
text: {
alignItems : 'center'
},
container: {
alignItems: 'center',
flex: 1,
},
buttonText1: {
borderWidth: 1,
padding: 25,
borderColor: 'black',
backgroundColor: '#C4D7ED',
alignItems: 'center',
position: 'absolute',
bottom: 0,
width: Dimensions.get('window').width / 2,
height: Dimensions.get('window').height / 8,
left: 0,
},
buttonText2: {
borderWidth: 1,
padding: 25,
borderColor: 'black',
backgroundColor: '#C4D7ED',
alignItems: 'center',
position: 'absolute',
bottom: 0,
width: Dimensions.get('window').width / 2,
height: Dimensions.get('window').height / 8,
right: 0,
}
});
AppRegistry.registerComponent('Project', () => Project);
Run Code Online (Sandbox Code Playgroud)
Has*_*Eqx 35
如果在 ios 14 或 xcode 12 中发生这种情况,您必须将 react native 升级到 0.63.2 react-native 版本中存在一个错误。
要修补低于 0.63.2 的 RN 版本的问题,请将其添加到Podfile.
pre_install do |installer|
puts("Image fix for ios14: remove this when upgradeing to >= 0.63.3")
find = "_currentFrame.CGImage;"
replace = "_currentFrame.CGImage ;} else { [super displayLayer:layer];"
op = `sed -ie "s/#{find}/#{replace}/" ../node_modules/react-native/Libraries/Image/RCTUIImageViewAnimated.m`
puts("Image fix for ios14 done")
end
Run Code Online (Sandbox Code Playgroud)
然后运行 pod install
或者,如果您想要基于包的解决方案,您可以使用https://www.npmjs.com/package/react-native-fix-image。如果您正在使用它,建议将其添加为 npm postinstall 脚本。
无需编辑 node_modules。
小智 17
为图像制作一些宽度和高度..
<Image
style={{width: 50, height: 50}}
source={{uri: 'https://facebook.github.io/react/img/logo_og.png'}}
resizeMode={'cover'} // cover or contain its upto you view look
/>
Run Code Online (Sandbox Code Playgroud)
我在这里提到了宽度和高度......你可以让它'100%'由你决定......
更新 IOS 14.x 后,生成的问题是未显示图像。这是一些反对的信息。
添加【super displayLayer:layer】后即可显示图片;如果 _currentFrame 为零
如果我理解正确,_currentFrame 应该是用于动画图像,所以如果它是静止图像,我们可以使用 UIImage 实现来处理图像渲染,不确定它是否正确修复。
node_modules/react-native/Libraries/Image/RCTUIImageViewAnimated.m
if (_currentFrame) {
layer.contentsScale = self.animatedImageScale;
layer.contents = (__bridge id)_currentFrame.CGImage;
} else {
[super displayLayer:layer];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
31706 次 |
| 最近记录: |