如何使用React Native从图片后面移动一个 buttom?

我已经附上了问题的截图。我似乎无法从图像对象后面移动我的按钮。我试过 zIndex 和移动我 Views 但我还是遇到了同样的问题。该代码似乎只在IOS上工作,但不在Android上。

我的代码如下。

我的代码如下,谢谢你。

项目截图

import * as React from 'react';
import { StyleSheet, Image, View } from 'react-native';
import * as ImagePicker from 'expo-image-picker';
import Constants from 'expo-constants';
import * as Permissions from 'expo-permissions';
import { EvilIcons } from '@expo/vector-icons'

export default class ImagePickerExample extends React.Component {
    state = {
        image: null,
    };

    render() {
        let { image } = this.state;

        return (
            <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
                <View style={styles.emptyProfile}>
                    {image && <Image source={{ uri: image }} style={styles.profile} />}
                </View>
                <View style={{ marginLeft: 70, justifyContent: 'center', bottom: 25 }}>
                    <View style={styles.camera}>
                        <EvilIcons name='camera' size={35} color='#fff' onPress={this._pickImage} />
                    </View>
                </View>
            </View>
        );
    }

    componentDidMount() {
        this.getPermissionAsync();
    }
    getPermissionAsync = async () => {
        if (Constants.platform.ios) {
            const { status } = await Permissions.askAsync(Permissions.CAMERA_ROLL);
            if (status !== 'granted') {
                alert('Sorry, we need camera roll permissions to make this work!');
            }
        }
    };

    _pickImage = async () => {
        try {
            let result = await ImagePicker.launchImageLibraryAsync({
                mediaTypes: ImagePicker.MediaTypeOptions.All,
                allowsEditing: true,
                aspect: [4, 4],
                quality: 1,
            });
            if (!result.cancelled) {
                this.setState({ image: result.uri });
            }

            console.log(result);
        } catch (E) {
            console.log(E);
        }
    };
}

const styles = StyleSheet.create({
    camera: {
        backgroundColor: '#fd4336',
        height: 50,
        width: 50,
        borderRadius: 25,
        justifyContent: 'center',
        alignItems: 'center',
        position: 'absolute',
    },
    profile: {
        width: 190,
        height: 190,
        borderRadius: 100,
        justifyContent: 'center',
        alignItems: 'center',
    },
    emptyProfile: {
        width: 200,
        height: 200,
        borderRadius: 100,
        backgroundColor: '#c1b78d',
        borderWidth: 5,
        borderColor: '#fff',
        shadowColor: 'black',
        shadowOffset: { width: 0, height: 3 },
        shadowRadius: 3,
        shadowOpacity: 0.3,
        elevation: 5
    }

})

截图

解决方案:

好吧,我想办法解决这个问题!通过包装另一个 View

 <View style={styles.emptyProfile}>
                {image && <Image source={{ uri: image }} style={styles.profile} />}
                <View style={{ left: 140, position: 'absolute', bottom: 50 }} >
                    <View style={styles.camera}>
                        <EvilIcons name='camera' size={35} color='#fff' onPress={this._pickImage} />
                    </View>
                </View>
            </View>
    );

本文来自投稿,不代表运维实战侠立场,如若转载,请注明出处:https://www.shizhanxia.com/463.html

(0)
上一篇 2022年6月29日 下午3:56
下一篇 2022年6月29日 下午3:56

相关推荐

发表评论

登录后才能评论