【问题标题】:Unwanted white bar below the screen屏幕下方不需要的白条
【发布时间】:2013-04-16 00:54:33
【问题描述】:

我有两个视图控制器,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];
}

请看下面白条的截图。

【问题讨论】:

  • 我不确定这与您的问题有什么关系,但您不应该访问应用程序委托来从 VC1 或 VC2 获取导航控制器。你应该使用 self.navigationController push ....

标签: ios objective-c


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

    我不明白你为什么使用 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;
    

    希望对你有帮助:)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-12
      • 1970-01-01
      • 1970-01-01
      • 2014-05-03
      • 2015-11-16
      • 2012-07-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多