在React Native中的zIndex

Ivo*_*rov 6 node.js ios reactjs react-native

如何处理zIndex?

我试图从scrollview中指定最大的数字,但它仍然在底部(

没有ScrollView它看起来像这样,但我需要向上滚动到图像.

谢谢

Fel*_*ipe 11

这已经在iOS中实现了0.30(参见提交更改)和android中的0.31(更改)

我已经为我如何使用它做了一个简单的示例组件:

'use-strict';

import React, { Component } from 'react';
const { View, StyleSheet } = require('react-native');

const styles = StyleSheet.create({
    wrapper: {
        flex:1,
    },
    back: {
        width: 100,
        height: 100,
        backgroundColor: 'blue',
        zIndex: 0
    },
    front: {
        position: 'absolute',
        top:25,
        left:25,
        width: 50,
        height:50,
        backgroundColor: 'red',
        zIndex: 1
    }
});

class Layers extends Component {
    constructor(props) {
        super(props);
    }

    render() {
        return (
            <View style={styles.wrapper}>
                <View style={styles.back}></View>
                <View style={styles.front}></View>
            </View>
        );
    }
}

module.exports = Layers;
Run Code Online (Sandbox Code Playgroud)

  • 所以在你的例子中,如果你颠倒顺序,加载'后'和'前'元素,zIndex仍然可以很好地发挥作用吗?我只问问因为现在你把它们装回到前面所以无论zIndex如何它都能正常工作,对吧? (2认同)
  • 注意:这仅适用于 iOS,当元素为 [siblings](https://facebook.github.io/react-native/docs/layout-props#zindex) 时。 (2认同)