2013-04-16 34 views
0

我有兩個視圖控制器,vc1和vc2。從vc1我去vc2,在vc2裏面我使用web視圖播放youtube視頻。當我回到vc1時,屏幕下方出現一個白色條。這是我的代碼。屏幕下方不需要的白條

/* From App Delegate to go vc1 */ 
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
    VC1 *vc1 = [[VC1 alloc] init]; 
    navigationController = [[UINavigationController alloc] init]; 
    [navigationController setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal]; 
    [navigationController setToolbarHidden:YES]; 
    [navigationController setNavigationBarHidden:YES]; 
    [navigationController setWantsFullScreenLayout:YES]; 
    [navigationController pushViewController:vc1 animated:FALSE]; 
    self.window.rootViewController = navigationController; 
    [self.window makeKeyAndVisible]; 
    return YES; 
} 

/* From VC1 to VC2 */ 
-(IBAction)gotoVC2:(id)sender 
{ 
    VC2 *vc2 = [[VC2 alloc] init]; 
    AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; 
    [appDelegate.navigationController vc2 animated:YES]; 
} 

/* Setting up YouTube View */ 
-(void) addYouTubeLink:(UIWebView*)webView url:(NSString*)url 
{ 
    for (UIView* shadowView in [webView.scrollView subviews]) 
    { 
     if ([shadowView isKindOfClass:[UIImageView class]]) { 
      [shadowView setHidden:YES]; 
     } 
    } 
    NSString *videoHTML = [NSString stringWithFormat:@"<html><head></head><body><iframe class=\"youtube-player\" type=\"text/html\" width=\"420\" height=\"315\" src=\"http://www.youtube.com/embed/%@\" align=\"middle\" frameborder=\"1\"></iframe></body></html>",url]; 
    [webView loadHTMLString:videoHTML baseURL:nil]; 
} 
/* Going Back to VC1 */ 
- (IBAction)goBack:(id)sender { 
    AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; 
    [appDelegate.navigationController setNavigationBarHidden:YES]; 
    [appDelegate.navigationController setWantsFullScreenLayout:YES]; 
    [appDelegate.navigationController popViewControllerAnimated:YES]; 
} 

請參閱以下白色欄的截圖。

screenshot

+0

我不知道這有什麼關係你的問題,但你不應該訪問應用程序委託從VC1或VC2獲取導航控制器。你應該使用self.navigationController推.... – rdelmar

回答

1

嘗試用根視圖控制器初始化您的導航控制器。

navigationController = [[UINavigationController alloc] initWithRootViewController:vc1]; 
+0

不,它沒有幫助。 – user1191140

0

我不明白爲什麼你用appDelegate.navigation控制器,因爲你可以啓動與RootViewController的導航控制器,並推動和彈出另一個控制器如果你想。

但關注您的情況,我認爲這是關於frame problem。在你的goback:sender方法中,在popViewControllerAnimated:之後按你想要的方式調整vc1's frame。要做到這一點,我認爲你應該在代碼中使用retain vc1控制器。像

@property (nonatomic, strong) UIViewController *vc1; 
在頭

,並

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
    { 
      VC1 *vc1 = [[VC1 alloc] init]; 
      self.vc1 = vc1; 

我希望它能幫助:)