2018-12-18 缩放方案

2018-12-18  本文已影响0人  056cc6443751

参照别人写的缩放方案试了下

var React = require('react-native')

var PixelRatio = React.PixelRatio;

const screenWidth = React.Dimensions.get('window').width;

const screenHeight = React.Dimensions.get('window').height;

const fontScale = PixelRatio.getFontScale();

const w = PixelRatio.getPixelSizeForLayoutSize(screenWidth);

const h = PixelRatio.getPixelSizeForLayoutSize(screenHeight);

const DEFAULT_WIDTH = 411;

const DEFAULT_HEIGHT = 683;

const MIN_SCALE = Math.min(screenHeight/DEFAULT_HEIGHT, screenWidth/DEFAULT_WIDTH);

export default class ScreenUtil {


     static caleHeight(value) {
        return screenHeight/DEFAULT_HEIGHT*value;
    }

    static caleHeight2(value) {
        return screenHeight/DEFAULT_HEIGHT*value;
    }

    static scaleFontSize(fontSize) {
         return fontSize*MIN_SCALE;
    }

    static scaleImageWidth(width) {
        return width*MIN_SCALE;
    }

    static scaleImageHeight(height) {
        return height*MIN_SCALE;
    }
}
上一篇 下一篇

猜你喜欢

热点阅读