你需要做的是在你的飛濺視圖控制器中處理。您可以使用組合interfaceOrientation,shouldAutorotateToInterfaceOrientation,didAutorotateToInterfaceOrientation等。
本質上,創建一個視圖控制器,您將擁有作爲您的根視圖控制器。在那裏,確定shouldAutorotateToInterfaceOrientation中的方向更改(它將始終是viewDidLoad中的縱向或橫向,具體取決於您的xib,因此請勿在此處執行此操作)。用NSTimer或其他方法顯示你的圖像。計時器後,顯示您的常規應用程序屏幕。
無論如何,只有擁有視圖控制器才能顯示圖像,因此您必須等到視圖控制器爲您提供interfaceOrientation更改。您應該關注第一個視圖控制器,而不是應用程序代理。
AppDelegate.h
#import <UIKit/UIKit.h>
@class SplashViewController;
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (retain, nonatomic) IBOutlet UIWindow *window;
@property (retain, nonatomic) SplashViewController *splashController;
-(void)showSplash;
@end
AppDelegate.m
#import "AppDelegate.h"
#import "SplashViewController.h"
@implementation AppDelegate
@synthesize window = _window, splashController = _splashController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[self showSplash];
[self.window makeKeyAndVisible];
[self performSelector:@selector(registerBackground) withObject:nil afterDelay:5.0];
return YES;
}
-(void)showSplash
{
SplashViewController *splash = [[SplashViewController alloc] initWithNibName:@"SplashViewController" bundle:nil];
[self.window addSubview:splash.view];
self.splashController = splash;
[splash release];
//have to add a delay, otherwise it will be called on initial launch.
[NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:@selector(removeSplash:) userInfo:nil repeats:NO];
}
-(void)registerBackground
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(returnFromBackground:)
name:UIApplicationDidBecomeActiveNotification
object:nil];
}
-(void)returnFromBackground:(NSNotification *)notification
{
[self showSplash];
}
-(void)removeSplash:(NSTimer *)timer
{
[self.splashController.view removeFromSuperview];
self.splashController = nil;
}
- (void)dealloc
{
[_window release];
[_splashController release];
[super dealloc];
}
什麼是你想在應用程序的委託呢?我問的原因是因爲界面方向幾乎總是用於視圖,這就是爲什麼它是UIViewController上的一個屬性...也許它可能會等到你呈現第一個視圖控制器? – Vinnie
我需要顯示一個與默認飛濺圖像相同的保持視圖,但方向性很好,這就是爲什麼我需要知道應用程序代理中的方向。 – hzxu