无论如何,启动图像都无法正常工作

时间:2013-11-30 07:33:47

标签: objective-c xcode image launch

我正在尝试将启动图像设置为我的应用程序,但是,无论我做什么,它都无法以正确的方式工作。

我的应用程序只是横向(左或右),但我还是只想放置一个纵向启动图像。

如果我选中“纵向”框并取消选中“部署信息”设置中的“向左移动”和“向右移动”框,则仅显示启动图像。显然我不能这样做,因为它会弄乱我的整个应用程序。

我尝试更改shouldAutorotateToInterfaceOrientation:在我的所有视图控制器中返回YES,但这不起作用。

感谢任何帮助。谢谢! -Xerif

1 个答案:

答案 0 :(得分:0)

我可能与你的相同,不幸的是我发现这是Xcode软件中的一个小错误/错误。我已经提出了可以在横向模式下显示启动图像而无需任何尺寸要求的代码!如果您有任何问题,请尽量跟上我并给我留言。以下是步骤:

  1. 使用NSObject的子类创建一个新的objective-c文件。将其命名为GameData。

  2. GameData.h中的
  3. 输入以下代码:

       #import <Foundation/Foundation.h>
    
       @interface GameData : NSObject
    
    
      @property (assign, nonatomic) int Mainint;
    
    
       +(instancetype)sharedGameData;
    
       @end 
    
  4. 现在在GameData.m中输入以下代码:

      #import "GameData.h"
    
     @implementation GameData
    
    
      + (instancetype)sharedGameData
      {
          static id sharedInstance = nil;
    
          static dispatch_once_t onceToken;
         dispatch_once(&onceToken, ^{
         sharedInstance = [[self alloc] init];
       });
         return sharedInstance;
       }
    
    
    
    
         -(void)launchImage
                      {
                   [GameData sharedGameData].Mainint = [[NSUserDefaults  standardUserDefaults]      integerForKey:@"mainint"];
             [[NSUserDefaults standardUserDefaults] setInteger:0 forKey:@"mainint"];
               }
    
  5. 现在进入AppDelegate.h文件并输入:

                #import "GameData.h"
    
  6. 现在进入AppDelegate.m文件并在以下方法中输入:

              - (BOOL)application:(UIApplication *)application    didFinishLaunchingWithOptions:    (NSDictionary *)launchOptions
                  {
    
    
                 [[NSUserDefaults standardUserDefaults] setInteger:0  forKey:@"mainint"]; //Add This
    
    
               // Override point for customization after application launch.
              return YES;
           }
    
  7. 现在进入故事板并将UILabel拖到初始View Controller或View控制器上,该控制器首次显示应用程序启动时。不要担心我们会隐藏这个标签,所以你不会看到它。

  8. 现在将UIImageView拖到初始View Controller的整个屏幕上

  9. 现在进入您的初始View Controllers .h文件(我的名为ViewController.h)并添加以下内容:

             #import <UIKit/UIKit.h>
             #import "GameData.h" //Add this
    
           @interface ViewController : UIViewController
    
           @property (weak, nonatomic) IBOutlet UIImageView *launchImage; //Add this
           @property IBOutlet UILabel *seconds; //Add this
           @property NSTimer *timer; //Add this
    
    
    
                       @end
    
  10. 现在进入初始视图控制器.m文件(我的是ViewController.m)并添加以下内容:

                   #import "ViewController.h"
    
    
                   @interface ViewController ()
    
                    @end
    
                   @implementation ViewController
    
                  @synthesize launchImage;
                  @synthesize timer;
                  @synthesize seconds;
    
    
                - (void)viewDidLoad
             {
    
    
               [GameData sharedGameData].Mainint = [[NSUserDefaults standardUserDefaults]    integerForKey:@"mainint"];
    
                   seconds.hidden = YES;
    
    
                   timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self   selector:@selector(countUp) userInfo:nil repeats:YES];
    
    
                      if ([GameData sharedGameData].Mainint > 3) {
    
                               launchImage.hidden = YES;
                      }
    
                           [self countUp];
    
                            [super viewDidLoad];
                    // Do any additional setup after loading the view, typically from a nib.
    
    
    
    
    
    
                                       }
    
    
    
    
                          - (void)didReceiveMemoryWarning
                          {
                        [super didReceiveMemoryWarning];
                   // Dispose of any resources that can be recreated.
                         }
    
    
    
    
    
    
    
    
    
               -(void)countUp
             {
    
    
                 [GameData sharedGameData].Mainint += 1;
                     seconds.text = [NSString stringWithFormat:@"%i", [GameData    sharedGameData].Mainint];
    
    
                    if ([GameData sharedGameData].Mainint == 3) {
    
                      launchImage.hidden = YES;
    
                       [GameData sharedGameData].Mainint = 4;
    
                          [[NSUserDefaults standardUserDefaults] setInteger:[GameData      sharedGameData].Mainint forKey:@"mainint"];
                            }
    
    
    
                               }
    
  11. 如果您完全遵循这些步骤,它应该有效,您应该没有问题。如果某些事情不起作用,请告诉我,我很乐意提供帮助。我搜索了几天和几天试图找到答案,然后通过测试此代码最终找出来。祝你好运!

相关问题