故事板/ XML / UIView如何避免改变位置

时间:2018-02-21 13:36:09

标签: ios xml xcode storyboard

我在xml中声明了一个故事板,

当我将xml cpoy /粘贴到实际的sotryboard中时,我的一些视图将被移动,因此元素的x,y宽度和高度将会不同。

该设计旨在符合iphone6标准。处理自动布局。但是,看起来像这样

<view contentMode="scaleAspectFit" fixedFrame="YES" insetsLayoutMarginsFromSafeArea="NO" translatesAutoresizingMaskIntoConstraints="NO" id="cz19r018cejc92w3fw">
<rect key="frame" x="0" y="600" width="375" height="66"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" widthSizable="YES" flexibleMaxX="YES" flexibleMinY="YES" heightSizable="YES" flexibleMaxY="YES"/>

将更改为

<view contentMode="scaleToFill" fixedFrame="YES" insetsLayoutMarginsFromSafeArea="NO" translatesAutoresizingMaskIntoConstraints="NO" id="cz19r018cejc92w3fw">
<rect key="frame" x="0.0" y="596" width="375" height="65"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" widthSizable="YES" flexibleMaxX="YES" flexibleMinY="YES" heightSizable="YES" flexibleMaxY="YES"/>

注意Y从600变为596,高度从66变为65.

知道如何避免这种行为吗?

编辑:

我正在使用Xcode 9.2,故事板被设置为View as: iPhone8 我正在生成完整的故事板本身,而不仅仅是一个视图。 这是一个产生行为的故事板。

<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13771" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="cz19r024cjc5x0ecx">
    <device id="retina4_7" orientation="portrait">
        <adaptation id="fullscreen"/>
    </device>
    <dependencies>
        <deployment identifier="iOS"/>
        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13772"/>
        <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
    </dependencies>
    <scenes>
        <!--View Controller-->
        <scene sceneID="cz19r024cjc5x0ecx-scene">
            <objects>
                <viewController id="cz19r024cjc5x0ecx" sceneMemberID="viewController">
                    <layoutGuides>
                        <viewControllerLayoutGuide type="top" id="cz19r024cjc5x0ecx-top"/>
                        <viewControllerLayoutGuide type="bottom" id="cz19r024cjc5x0ecx-bottom"/>
                    </layoutGuides>
                    <view key="view" contentMode="scaleAspectFit" id="view-cz19r024cjc5x0ecx">
                        <rect key="frame" x="0.0" y="0.0" width="375" height="672"/>
                        <autoresizingMask key="autoresizingMask" flexibleMinX="YES" widthSizable="YES" flexibleMaxX="YES" flexibleMinY="YES" heightSizable="YES" flexibleMaxY="YES"/>
                        <subviews>
                            <view contentMode="scaleToFill" fixedFrame="YES" insetsLayoutMarginsFromSafeArea="NO" translatesAutoresizingMaskIntoConstraints="NO" id="cz19r018cejc92w3fw">
                                <rect key="frame" x="0" y="600" width="375" height="66"/>
                                <autoresizingMask key="autoresizingMask" flexibleMinX="YES" widthSizable="YES" flexibleMaxX="YES" flexibleMinY="YES" heightSizable="YES" flexibleMaxY="YES"/>
                                <color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
                            </view>
                        </subviews>
                        <color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
                    </view>
                    <extendedEdge key="edgesForExtendedLayout"/>
                    <nil key="simulatedTopBarMetrics"/>
                    <nil key="simulatedBottomBarMetrics"/>
                </viewController>
                <placeholder placeholderIdentifier="IBFirstResponder" id="placeholderId-cz19r024cjc5x0ecx" userLabel="First Responder" sceneMemberID="firstResponder"/>
            </objects>
        </scene>
    </scenes>
</document>

1 个答案:

答案 0 :(得分:0)

完整xml中的第21行是错误的:

updateChildren()

它应该是:

FirebaseUser user=FirebaseAuth.getInstance().getCurrentUser();
String useruid=user.getUid();
DatabaseReference ref=FirebaseDatabase.getInstance().getReference().child("Accounts").child("user").child(useruid);
Map<String, Object> updates = new HashMap<String,Object>();

updates.put("date", newdate);
updates.put("email", newemail);
updates.put("name", newname);
updates.put("type", newtype);

ref.updateChildren(updates);

<rect key="frame" x="0.0" y="0.0" width="375" height="672"/> 代替<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>