首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在所需的方向上添加childViewController

如何在所需的方向上添加childViewController
EN

Stack Overflow用户
提问于 2014-08-25 07:25:33
回答 1查看 266关注 0票数 0

我有一个parentViewController在potrait模式中,我想在景观模式中向它添加childViewController(它是MPMoviePlaycontroller的一个子类)--这是我正在使用的代码:

ParentViewController.m中的

代码语言:javascript
复制
-(IBAction)playMovie
{
     ChildViewController *childViewController = [[ChildViewController alloc] initWithContentURL:url];

    [self.navigationController.view addSubview:childViewController.view];
    childViewController.view.alpha = 0.0;
    [childViewController beginAppearanceTransition:YES animated:YES];
    [UIView
     animateWithDuration:0.3
     delay:0.0
     options:UIViewAnimationOptionCurveEaseOut
     animations:^(void){
         childViewController.view.alpha = 1.0;
     }
     completion:^(BOOL finished) {
         [childViewController endAppearanceTransition];
         [childViewController didMoveToParentViewController:self.navigationController];
     }
     ];

}

儿童视图控件中的.m

代码语言:javascript
复制
-(BOOL)shouldAutorotate {
    return YES;
}

-(NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskLandscape;
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
}

问题是ChildViewController仍然以纵向模式显示。

EN

回答 1

Stack Overflow用户

发布于 2014-08-25 10:56:15

ChildViewController *childViewController = [ChildViewController alloc initWithContentURL:ChildViewController];

addChildViewController:childViewController; self.navigationController

self.navigationController.view addSubview:childViewController.view;

子视图控制器应该先添加到其父视图控制器中,然后再访问它的视图。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25480906

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档