0

我有一个包含三个视图的基本应用程序,第一个视图(初始视图)有一个 ImageView,其中包含一个 320 x 460(我也尝试过 320 x 480)的图像,作为视图的背景图像。状态栏已启用。当我在手机上测试应用程序时,图像会在应用程序首次加载并最终缩放以适应屏幕时调整大小。我的图像尺寸做错了什么?由于图像大小调整,当应用程序首次加载时,初始视图似乎“跳跃”,我不希望用户认为存在问题。

这是我的故事板:

<objects>
            <placeholder placeholderIdentifier="IBFirstResponder" id="vni-Jh-JGC" userLabel="First Responder" sceneMemberID="firstResponder"/>
            <viewController id="gWY-GQ-C35" sceneMemberID="viewController">
                <view key="view" contentMode="scaleToFill" id="e8S-C8-ddz">
                    <rect key="frame" x="0.0" y="20" width="320" height="460"/>
                    <autoresizingMask key="autoresizingMask"/>
                    <subviews>
                        <imageView autoresizesSubviews="NO" userInteractionEnabled="NO" contentMode="scaleToFill" image="targetbg.png" id="s7d-M3-VIr">
                            <rect key="frame" x="-1" y="0.0" width="320" height="460"/>
                            <autoresizingMask key="autoresizingMask"/>
                            <rect key="contentStretch" x="0.0" y="0.0" width="0.0" height="0.0"/>
                        </imageView>
                        <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" id="uF7-4u-0PX">
                            <rect key="frame" x="14" y="417" width="300" height="38"/>
                            <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
                            <fontDescription key="fontDescription" type="boldSystem" pointSize="15"/>
                            <state key="normal" image="newsubmit.png">
                                <color key="titleColor" red="0.19607843459999999" green="0.30980393290000002" blue="0.52156865600000002" alpha="1" colorSpace="calibratedRGB"/>
                            </state>
                            <state key="highlighted">
                                <color key="titleColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
                            </state>
                            <connections>
                                <segue destination="2" kind="modal" id="Qkv-0y-8Sh"/>
                            </connections>
                        </button>
                        <label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="Blake Design Group" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="10" id="Am2-mX-6Yv">
                            <rect key="frame" x="22" y="386" width="280" height="21"/>
                            <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
                            <fontDescription key="fontDescription" type="system" pointSize="10"/>
                            <color key="textColor" red="1" green="1" blue="1" alpha="1" colorSpace="calibratedRGB"/>
                            <nil key="highlightedColor"/>
                        </label>
                        <label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="version 2.0" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="10" id="Buw-jD-jIs">
                            <rect key="frame" x="16" y="374" width="280" height="21"/>
                            <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
                            <fontDescription key="fontDescription" type="system" pointSize="10"/>
                            <color key="textColor" red="1" green="1" blue="1" alpha="1" colorSpace="calibratedRGB"/>
                            <nil key="highlightedColor"/>
                        </label>
                    </subviews>
                    <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
                </view>
                <nil key="simulatedTopBarMetrics"/>
                <simulatedOrientationMetrics key="simulatedOrientationMetrics"/>
                <simulatedScreenMetrics key="simulatedDestinationMetrics"/>
            </viewController>
        </objects>
4

2 回答 2

0

我将假设您正在尝试创建启动画面这是我为使启动画面适用于 iPhone 和 iPad 所做的工作

  • 我创建一个UIView(我的启动视图)不是UIViewController
  • 首先创建一个大小为 320*460 的视图
  • 添加a UIImageView,imageView大小为320*460,y设置为-10
  • UIImageView和容器的UIView调整大小掩码设置为 0(根本没有调整大小)
  • UIImageView内容设置为center
  • willMoveToSuperview我有以下

    - (void)willMoveToSuperview:(UIView *)newSuperview
    {  
        BOOL isiPad = UIUserInterfaceIdiomPad == UI_USER_INTERFACE_IDIOM();
    
        if(isiPad)
        {
            mainImage.image = [UIImage newImageFromResource:@"Default-Portrait~ipad.png"];            
        }
        else {
            mainImage.image = [UIImage newImageFromResource:@"Default"];                    
        }
    }
    
  • 现在在didFinishLaunchingWithOptions我创建这个视图并将其添加到self.window.rootViewController

    [self.window.rootViewController.view addSubview:splashScreen];
    splashScreen.frame = self.window.rootViewController.view.bounds;
    splashScreen.autoresizingMask = AUTORESIZE_ALL;
    [splashScreen initialize];
    

这在方向和 iPad 和 iPhone 上都对我有用,

注意:我使用相同的 default.png 图像来创建启动画面

于 2012-06-16T18:45:48.497 回答
0

我终于弄明白了,它是如此简单。我的启动图像是 480,我的 bg 图像是 460。这在加载过程中造成了短暂的重叠,并创建了似乎是调整大小/重新缩放的内容。今天吸取了很好的教训。

于 2012-06-16T21:25:52.283 回答