Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone UIViewController和方向我的方向正确吗?_Iphone_Uiview_Uiviewcontroller - Fatal编程技术网

Iphone UIViewController和方向我的方向正确吗?

Iphone UIViewController和方向我的方向正确吗?,iphone,uiview,uiviewcontroller,Iphone,Uiview,Uiviewcontroller,在过去的几个小时里,我一直在努力让它发挥作用,但我做不到,所以我需要知道我所做的是否正确。我快发疯了 我的目标是拥有一个能够检测方向变化的ViewController。当它是纵向视图时,它显示一个带有UITableView的视图;当它是横向视图时,它显示一个带有我将以编程方式创建的内容的UIView 在父视图控制器中,我有: - (void)viewDidLoad { [super viewDidLoad]; TableDataViewController *tableDataCon

在过去的几个小时里,我一直在努力让它发挥作用,但我做不到,所以我需要知道我所做的是否正确。我快发疯了

我的目标是拥有一个能够检测方向变化的ViewController。当它是纵向视图时,它显示一个带有UITableView的视图;当它是横向视图时,它显示一个带有我将以编程方式创建的内容的UIView

在父视图控制器中,我有:

- (void)viewDidLoad 
{
    [super viewDidLoad];

TableDataViewController *tableDataController = [[TableDataViewController alloc]  
          initWithNibName:@"TableDataViewController"                                                                                
                   bundle:nil];
self.tableDataViewController = tableDataController;
[self.view insertSubview: tableDataController.view atIndex:0];
[tableDataController release];
}
这将加载我的视图,其中包含表视图及其附带的控制器。然后,用户旋转设备和功能:

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toOrientation                                                 
duration:(NSTimeInterval)duration
{
if (toOrientation == UIInterfaceOrientationPortrait) {
    NSLog(@"PerformAnalysisViewController: Gone to Potrait");   
} 

if ((toOrientation == UIInterfaceOrientationLandscapeLeft) || 
    (toOrientation == UIInterfaceOrientationLandscapeRight)) {
    NSLog(@"PerformAnalysisViewController: Gone to Landscape");

           // Load new view here
           CGRect frame = [[UIScreen mainScreen] applicationFrame];
       UIView *horizView = [[[HorizView alloc]
                  initWithFrame:frame] autorelease];
       [self setView:horizView];;   
}
}
将根据具体情况触发。但是它不会触发?这是因为控件已传递给我在viewDidLoad中插入的子视图吗?如果是这样的话,我该如何取回它?我是否必须让它检测方向,然后将自身从superview中移除

如果这是可行的,那么新的视图是否会像我上面所说的那样被添加?我已经试过阅读苹果的文档,但我无法做到这一点

非常感谢大家的帮助


Mike

我使用willRotateToInterfaceOrientation方法来处理UI旋转:

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration {
   if( interfaceOrientation == UIInterfaceOrientationPortrait || 
       interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown ) {
      self.backgroundImageView.image = [UIImage imageNamed:@"vertical.png"];
   }
   else {
      self.backgroundImageView.image = [UIImage imageNamed:@"horizontal.png"];
   }

}

请查收,您的Info.plist支持多个方向,并且您已经通过返回YES实现了shouldAutorotateToInterfaceOrientation:interfaceOrientation。

您是否通过返回YES实现了shouldAutorotateToInterfaceOrientation:interfaceOrientation?它似乎没有触发-尽管在中设置了Info.pist并返回YES应该自动旋转指向面方向:界面方向OK,我自己解决了。我删除了类文件,并重新开始,我必须以某种方式破坏它。