我目前有一个基本的1页iOS的React Native应用程序(iPad 4),用于显示相机供稿并覆盖图像序列。该图像序列由149帧组成,并且连续循环。
我Image
每秒更换组件源24次,从而实现了图像序列循环。
这是应用程序类(没有样式道具)。
class App extends Component {
constructor(props) {
super(props);
this.state = {
frame: 1
};
}
componentDidMount() {
setInterval(() => {
let frame = this.state.frame;
frame++;
if (frame > 149) {
frame = 1;
}
this.setState({frame});
}, 1000 / 24);
}
render() {
return (
<View style={styles.container}>
<Camera ref={(cam) => {this.camera = cam}}>
<Text>Frame: {this.state.frame}</Text>
<Image source={{uri: `./gifs/${this.state.frame}.gif`}}/>
</Camera>
</View>
);
}
}
将其作为输出。
我遇到的问题是,应用程序在更改时间长度后会崩溃。有时它可以在崩溃前运行3秒,有时可以在崩溃前运行2分钟。
我猜这是一个内存问题,但是在Xcode的调试器中,它仅使用约10%的可用内存。是否有办法只将所需的图像加载到内存中并删除不需要的图像,或者这是自动管理的?
尝试react-native-sprite,它使用本机UIImageView
而不是javascript setInterval解决方案对图像序列进行动画处理。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句