2014-01-30 110 views
0

我想在應用程序啓動的開始時顯示視頻,就像飛濺。我的整個應用程序將在導航。首先,我將視頻添加到splashViewController中,並將其作爲rootView設置在appDelegate中,然後再次將mainViewController設置爲rootView。添加視頻作爲故事板上的飛濺ios7

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil]; 
    splashViewController = [[SplashViewController alloc] init]; 
    splashViewController = (SplashViewController *)[mainStoryboard instantiateViewControllerWithIdentifier:@"SplashViewController"]; 
    self.window.rootViewController = splashViewController; 

    [NSTimer scheduledTimerWithTimeInterval:9.0 target:self selector:@selector(removeSplashScreen:) userInfo:nil repeats:NO]; 

    return YES; 
} 

-(void)removeSplashScreen:(id)userInfo 
{ 
    [splashViewController removeFromParentViewController]; 

    UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil]; 
    mainViewController = [[MainViewController alloc] init]; 
    mainViewController = (MainViewController *)[mainStoryboard instantiateViewControllerWithIdentifier:@"MainViewController"]; 
    self.window.rootViewController = mainViewController; 
} 

現在我想從這個mainViewController開始導航。我使用storyBoard &在mainViewController中添加來自Editor > Embed in > Navigation Controller的導航。不要以編程方式進行。但我知道使用Nib.xib來實現它的方式。在這裏,我還將arrow(表示啓動VC的箭頭)標記放在它旁邊。但是當我點擊一個從mainVC到下一個VC的按鈕時它會崩潰。我怎樣才能在這裏設置導航?

如果有人有答案,請與我分享。非常感謝Advance。

我的故事板的場景:

enter image description here

+0

如果你讀了蘋果人機界面指南您將看到啓動畫面不推薦它。沒有諸如啓動畫面的概念,而是啓動圖像。請記住,不遵循該指南可能會導致應用程序拒絕 – meda

+0

感謝您評論並提醒指南。但我想這樣做。在過去的筆尖文件我做視頻飛濺和應用程序商店的應用程序永遠不會拒絕它。 – Tulon

+0

我同意'meda'不堅持準則會拒絕你的應用程序。儘管你所追求的並不違背準則,因爲這只是一個播放視頻的「UIViewController」。所以從我的理解你的應用程序將啓動,用戶將看到啓動圖像,然後第一個視圖控制器呈現本身將是'SplashViewController'。這似乎沒有什麼,但我會注意到,這與'xcode IDE'無關,所以請不要使用該標籤。 – Popeye

回答

1

高興能在這裏幫助你在兩個步驟

第1步 - 您didFinishLaunchingWithOptions代碼幾乎是正確的,但它的工作無關緊要。所以讓我們把重點放在第二步。

步驟2-在 - (無效)removeSplashScreen:(ID)USERINFO

-first line is good , but you even dont need it because you are going to switch the root controller (leave it for now) 
    - second line (no need to write it) 
    - third line is really bad , what you doing here is trying to alloc you mainviewcontroller. really you need it with storyboard? no 
    - you should load you main view controller from storyboard 
    MainViewController* mainViewController = (MainViewController *)[mainStoryboard instantiateViewControllerWithIdentifier:@"MainViewController"]; 

「這條線是足以載入從故事板的主視圖控制器」 - 下行是正確
self.window .rootViewController = mainViewController; 代碼似乎現在正在工作,但仍然缺少導航控制器,因爲您已經從故事板加載了mainviewcontroller,而不是導航控制器。

- two solution for it 
1- load navigation controller in place of mainviewcontroller(give a storyboard id to navigation controller , load it , and make it as root controller) --i will always go with it 
2- make a navigation controller with allocating it & make its rootviewcontroller the mainviewcontroller 

-----------------工作代碼---------------

+0

非常感謝pawan。這是工作 :)。我去找你的第二個解決方案。 >>「2-分配一個導航控制器並將它的rootviewcontroller設置爲mainviewcontroller」,但這裏會做一些修改。這是「2-使導航控制器分配它並使其rootviewcontroller成爲navigationController」。非常感謝您的解釋和給予選擇。 :) – Tulon

1

好吧儘管我的建議(在評論),這裏是你如何能做到這一點:

顯示飛濺:

//StoryBoard 
UIStoryboard *mainStoryboard = [UIStoryboard 
            storyboardWithName:@"Main" bundle: nil]; 
//Splash Controller         
SplashViewController *splashViewController = [mainStoryboard 
       instantiateViewControllerWithIdentifier:@"SplashViewController"]; 
//Show it         
[self.window.rootViewController presentViewController:splashViewController 
              animated:NO completion:nil]; 

刪除它:

[self dismissViewControllerAnimated:YES completion:nil]; 

編輯:還沒工作?

也許你稱它爲快速。做到這一點:

viewDidLoad中

[NSTimer scheduledTimerWithTimeInterval:9.0 
            target:self 
            selector:@selector(removeSplashScreen:) 
            userInfo:nil repeats:NO]; 

函數刪除:

-(void)removeSplashScreen:(id)userInfo 
{ 
    [self dismissViewControllerAnimated:YES completion:nil]; 
} 
+0

雖然我同意你的建議,但他們試圖達到的目的並不違背它。這些指導方針指的是啓動圖像是什麼發生在你之後(按說),因此添加一個視圖控制器(就像它就是這樣)播放視頻是完全可以接受的,這在任何地方都是不允許的。 – Popeye

+0

是的。這是我的觀點。這不像我不在這裏添加任何飛濺。我做到了。但之後,只是想添加splashVC。而已。 – Tulon

+0

是的,你們是對的,我是誰來判斷。 – meda

0

所以該溶液中,根據到爬完的給出的答案是:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil]; 
    splashViewController = (SplashViewController *)[mainStoryboard instantiateViewControllerWithIdentifier:@"SplashViewController"]; 
    self.window.rootViewController = splashViewController; 

    [NSTimer scheduledTimerWithTimeInterval:9.0 target:self selector:@selector(removeSplashScreen:) userInfo:nil repeats:NO]; 

    return YES; 
} 

-(void)removeSplashScreen:(id)userInfo 
{ 
    UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil]; 
    mainViewController = [[MainViewController alloc] init]; 
    mainViewController = (MainViewController *)[mainStoryboard instantiateViewControllerWithIdentifier:@"MainViewController"]; 

    navigationContoller = [[UINavigationController alloc] initWithRootViewController:mainViewController]; 
    self.window.rootViewController = navigationContoller; 
} 

:)