我有两个视图控制器,vc1和vc2。 从vc1转到vc2,在vc2内使用网络视图播放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];
}

请参见下面白色栏的屏幕截图。

屏幕截图

===============>>#1 票数:1

尝试使用根视图控制器初始化导航控制器。

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

===============>>#2 票数:0

我不明白为什么要使用appDelegate.navigation控制器,因为您可以使用rootViewController初始化导航控制器,并根据需要推送和弹出另一个控制器。

但是,重点关注您的情况,我认为这与frame problem goback:sender方法中,在popViewControllerAnimated:之后popViewControllerAnimated:以所需方式调整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;

希望对您有所帮助:)

  ask by user1191140 translate from so

未解决问题?本站智能推荐: