[英]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.谢谢。
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 & 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 & 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 回答,您可能使用了填充屏幕的背景图像并且它有问题,如果标签出现,请确保将标签放在明亮的颜色上,然后记住这一点:
Some root causes for this could be造成这种情况的一些根本原因可能是
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.