我有两个视图控制器,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];
}
请参阅下面白色栏附带的截图。
答案 0 :(得分:1)
尝试使用根视图控制器初始化导航控制器。
navigationController = [[UINavigationController alloc] initWithRootViewController:vc1];
答案 1 :(得分: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;
我希望它有所帮助:)