简体   繁体   English

将 Visual Studio 2017 与 Xamarin 结合使用 - iOS 启动屏幕为黑色/空白

[英]Using Visual Studio 2017 with Xamarin - iOS Launchscreen is black/blank

I'm stumped.我难住了。 When I created the project, the LaunchScreen.xib was displaying it's default content that you get when you create a iOS project in Visual Studio.当我创建项目时,LaunchScreen.xib 显示的是您在 Visual Studio 中创建 iOS 项目时获得的默认内容。 No problem.没问题。 I decided that I would edit the xib, added a label and a image, now it won't display, on launch of the application I get a black screen.我决定编辑 xib,添加一个标签和一个图像,现在它不会显示,在应用程序启动时我得到一个黑屏。 So I deleted everything I added to the xib, figured that would at least get me back to the original launch screen.所以我删除了我添加到 xib 的所有内容,认为这至少会让我回到原来的启动屏幕。 Nope, still loads black.不,仍然加载黑色。 I've searched all over the web and tried every "fix" I could find.我搜索了整个网络并尝试了我能找到的所有“修复”。 Still black.还是黑的。 Tried using Storyboard, creating another xib (MyLaunchScreen.xib), still loads black.尝试使用 Storyboard,创建另一个 xib (MyLaunchScreen.xib),仍然加载黑色。 It seems that as soon as I touched the original xib, it went to hell in a hand basket.好像一摸到原来的xib,就在手篮里下地狱了。 If any has any suggestions on how this can be resolved, I would appreciate it.如果有人对如何解决此问题有任何建议,我将不胜感激。 Thanks.谢谢。

Maybe you made something corrupt with original .xib也许您使用原始 .xib 制作了一些损坏的东西

Try the following steps:尝试以下步骤:

  1. Uninstall your app in the simulator.在模拟器中卸载您的应用程序。

  2. Delete original .Xib删除原始.Xib

  3. Create a new .Storyboard or .Xib file创建一个新的.Storyboard.Xib文件

  4. Select the new file in info.plistinfo.plist选择新文件

在此处输入图片说明

I found a solution that worked for me, first a little background: The only answer I could find on the web that was specific to my issue uses Visual Studio 2015. The answer said to create my own launch screen by right clicking on Resources and adding a "LaunchScreen.xib" to the resources folder, there was no such option in 2017. Apparently Visual Studio has changed a little so that when your right click on the Resources folder and add a new item, it allows you to select a "View" which is a .xib.我找到了一个对我有用的解决方案,首先是一些背景知识:我在网上找到的唯一一个针对我的问题的答案使用 Visual Studio 2015。答案说通过右键单击资源并添加来创建我自己的启动屏幕一个“LaunchScreen.xib”到资源文件夹,2017 年没有这样的选项。显然 Visual Studio 已经改变了一点,所以当你右键单击资源文件夹并添加一个新项目时,它允许你选择一个“视图"这是一个 .xib。 I did that and got what I was looking for, added the labels and image view I wanted and now all works as I want.我这样做并得到了我想要的东西,添加了我想要的标签和图像视图,现在一切都按我想要的方式工作。 I'm pretty sure that the issue was due to the constraints built into the default LaunchScreen.xib, the constraint system used in Xamarin for Visual Studio 2017 confuses the bejesus out of me so the LaunchScreen.xib I created has no constraints.我很确定问题是由于默认 LaunchScreen.xib 中内置的约束造成的,Xamarin for Visual Studio 2017 中使用的约束系统让我感到困惑,因此我创建的 LaunchScreen.xib 没有任何约束。 This may bite me later when I attempt to release the app on the Apple Store, but I'll deal with that later.稍后当我尝试在 Apple Store 上发布该应用程序时,这可能会困扰我,但我稍后会处理。 Below is the LaunchScreen.xib, which is nothing more that an XML file, that does not work followed by the one that does not, maybe someone can explain the whole constraint thing to me that makes sense to me.下面是 LaunchScreen.xib,它只不过是一个 XML 文件,它不起作用,然后是一个不起作用的文件,也许有人可以向我解释整个约束对我有意义的事情。 Right now, ugh.现在,呃。

LaunchScreen.xib (excuse the formatting if I don't get it exactly right): LaunchScreen.xib(如果我不完全正确,请原谅格式):

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="11762" systemVersion="15G18013" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" colorMatched="YES">
        <dependencies>
            <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11757"/>
            <capability name="Constraints with non-1.0 multipliers" minToolsVersion="5.1"/>
            <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
        </dependencies>
            <objects>
                <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
                <placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
                     <view contentMode="scaleToFill" id="iN0-l3-epB">
                         <rect key="frame" x="0.0" y="0.0" width="480" height="480"/>
                         <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                     <subviews>
                         <label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="  Copyright (c) 2017 C &amp; G Associates, Inc." textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="9" translatesAutoresizingMaskIntoConstraints="NO" id="8ie-xW-0ye">
                             <rect key="frame" x="20" y="439" width="440" height="21"/>
                             <fontDescription key="fontDescription" type="system" pointSize="17"/>
                             <color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
                             <nil key="highlightedColor"/>
                        </label>
                        <label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Sample Out" textAlignment="center" lineBreakMode="middleTruncation" baselineAdjustment="alignBaselines" minimumFontSize="18" translatesAutoresizingMaskIntoConstraints="NO" id="kId-c2-rCX" misplaced="YES">
                            <rect key="frame" x="20" y="36" width="440" height="43"/>
                            <fontDescription key="fontDescription" name="TimesNewRomanPS-BoldItalicMT" family="Times New Roman" pointSize="36"/>
                            <color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
                            <nil key="highlightedColor"/>
                       </label>
                   </subviews>
                   <color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
                   <constraints>
                       <constraint firstItem="kId-c2-rCX" firstAttribute="centerY" secondItem="iN0-l3-epB" secondAttribute="bottom" multiplier="1/3" constant="1" id="5cJ-9S-tgC"/>
                       <constraint firstAttribute="centerX" secondItem="kId-c2-rCX" secondAttribute="centerX" id="Koa-jz-hwk"/>
                       <constraint firstAttribute="bottom" secondItem="8ie-xW-0ye" secondAttribute="bottom" constant="20" id="Kzo-t9-V3l"/>
                       <constraint firstItem="8ie-xW-0ye" firstAttribute="leading" secondItem="iN0-l3-epB" secondAttribute="leading" constant="20" symbolic="YES" id="MfP-vx-nX0"/>
                       <constraint firstAttribute="centerX" secondItem="8ie-xW-0ye" secondAttribute="centerX" id="ZEH-qu-HZ9"/>
                       <constraint firstItem="kId-c2-rCX" firstAttribute="leading" secondItem="iN0-l3-epB" secondAttribute="leading" constant="20" symbolic="YES" id="fvb-Df-36g"/>
                   </constraints>
                   <nil key="simulatedStatusBarMetrics"/>
                   <freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
                   <point key="canvasLocation" x="548" y="455"/>
                   <accessibility key="accessibilityConfiguration">
                        <bool key="isElement" value="YES"/>
                   </accessibility>
                   <connections>
                       <outlet property="lblCopyRight" destination="8ie-xW-0ye" id="name-outlet-8ie-xW-0ye"/>
                   </connections>
                </view>
            </objects>
            <resources>
                <image name="CarpetSample.png" width="1294" height="861"/>
            </resources>
</document>

MyLaunchScreen.xib (this works): MyLaunchScreen.xib(这个有效):

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="11762" systemVersion="15G18013" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" launchScreen="YES">
    <device id="ipad9_7" orientation="portrait">
        <adaptation id="fullscreen"/>
    </device>
    <dependencies>
        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11757"/>
        <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
    </dependencies>
    <objects>
        <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
        <placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
        <view contentMode="scaleToFill" id="1">
            <rect key="frame" x="0.0" y="0.0" width="768" height="1024"/>
            <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
            <color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
            <subviews>
                <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Sample Out" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="165" translatesAutoresizingMaskIntoConstraints="NO" fixedFrame="YES">
                    <rect key="frame" x="0.0" y="29" width="768" height="58"/>
                    <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
                    <fontDescription key="fontDescription" name="TimesNewRomanPS-BoldItalicMT" family="Times New Roman" pointSize="36"/>
                    <nil key="textColor"/>
                    <nil key="highlightedColor"/>
                </label>
                <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="268" translatesAutoresizingMaskIntoConstraints="NO" fixedFrame="YES" text="Copyright (c) 2017 C &amp; G Associates, Inc.">
                    <rect key="frame" x="0.0" y="943" width="768" height="45"/>
                    <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
                    <fontDescription key="fontDescription" type="system" pointSize="17"/>
                    <nil key="textColor"/>
                    <nil key="highlightedColor"/>
                </label>
                <imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" id="328" translatesAutoresizingMaskIntoConstraints="NO" fixedFrame="YES" image="CarpetSample.png">
                    <rect key="frame" x="43" y="111" width="685" height="806"/>
                    <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
                </imageView>
            </subviews>
        </view>
    </objects>
    <resources>
        <image name="CarpetSample.png" width="1294" height="861"/>
    </resources>
</document>

If anybody else coming here follow Cole Xia - MSFT answer above, you probably using background image that fill the screen and it has something wrong with it, to make sure put label on top with bright color if the label appears then keep this mind:如果其他人跟随 Cole Xia - 上面的 MSFT 回答,您可能使用了填充屏幕的背景图像并且它有问题,如果标签出现,请确保将标签放在明亮的颜色上,然后记住这一点:

  1. To avoid any properties you may have changed before it is better to create a new View .xib为避免您在创建新视图 .xib 之前可能已更改的任何属性
  2. when you run it try using different simulator (ie like iphone 6, iphone 7 etc) or uninstall it before to avoid any caching saved in the device.当您运行它时,请尝试使用不同的模拟器(例如 iphone 6、iphone 7 等)或先卸载它以避免在设备中保存任何缓存。
  3. Usually the cause is the constraints that make the image responsive to different screen sizes, if not done properly will make it confuse and show it black, you can design it to one device size then check in design mode for other devices, it should tell you by red dots square calculated position or you will notice it is stretching check this video https://youtu.be/i54LzXWwLuc also in layout check that you have only four constraints if you stretching your bg image in four directions.通常原因是限制使图像响应不同的屏幕尺寸,如果做得不好会使其混淆并显示为黑色,您可以将其设计为一种设备尺寸然后检查其他设备的设计模式,它应该告诉您通过红点正方形计算位置,否则您会注意到它正在拉伸 检查此视频https://youtu.be/i54LzXWwLuc也在布局检查中,如果您在四个方向上拉伸 bg 图像,您只有四个约束。
  4. Check also here how to make image background in splash https://stackoverflow.com/a/47749043/10327213也在这里检查如何在飞溅中制作图像背景https://stackoverflow.com/a/47749043/10327213

Some root causes for this could be造成这种情况的一些根本原因可能是

  • Misconfiguration in info.plist. info.plist 中的错误配置。 Since iOS 8, iOS accepts universal launch screen storyboard.从 iOS 8 开始,iOS 接受通用启动屏幕故事板。 The name for launch screen in info.plist should match the actual launch screen name. info.plist 中启动屏幕的名称应与实际启动屏幕名称匹配。
  • Launch screen Storyboard/XIB file got corrupted.启动屏幕 Storyboard/XIB 文件已损坏。 Storyboard and XIB files can get corrupted sometimes.故事板和 XIB 文件有时会损坏。 We may be able to figure it out by checking the XML source of the file.我们或许可以通过检查文件的 XML 源代码来弄清楚。 In my case, I had copied some view controllers from another storyboard file and deleted some of the existing ones.就我而言,我从另一个故事板文件中复制了一些视图控制器并删除了一些现有的。 Each view controller has a unique id in the storyboard.每个视图控制器在故事板中都有一个唯一的 id。 My Storyboard was keeping the id of a deleted View controller as the initialViewController .我的 Storyboard 将已删除的 View 控制器的 id 保留为initialViewController By changing the value of this property to the id of a valid viewcontroller that existed in storyboard, the issue got fixed for me.通过将此属性的值更改为故事板中存在的有效视图控制器的 id,我解决了这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM