0

我正在向应用程序添加 UIInterfaceOrientation 更改。我的应用程序不是基于选项卡或导航的。我在其他之上添加子视图。

我浏览了文档为什么界面方向更改不起作用? http://developer.apple.com/library/ios/#qa/qa1688/_index.html

我发现主窗口控制界面方向的变化。

但是现在由于我的应用不是基于标签或基于导航的,还有什么方法可以实现吗?

PS:在我的应用程序中,只有启动屏幕才能正常工作,用于界面方向更改,而不是添加的子视图。

请帮忙

提前致谢。

4

2 回答 2

1

使用以下方法调整子视图的大小。或使用autoresizingMask

 -(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
  {
    if(toInterfaceOrientation == UIInterfaceOrientationPortrait){

        viewInformationContainer.frame = CGRectMake(0, 61, 320, 403);// here you can change resize or subviews


    }
    else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight || toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) {

        viewInformationContainer.frame = CGRectMake(0, 0, 480, 227);//here you can change resize or subviews


        }
}

希望对你有帮助...

于 2012-05-11T03:38:07.537 回答
1

阅读上面发布的评论,您面临的问题是我可以说您添加了子视图的层次结构。考虑以下情况

1)我将视图控制器(VC),导航控制器,标签栏控制器直接添加到窗口。后续视图将正确通知任何方向更改。

2)我向窗口添加了一个父视图控制器,然后将一些其他视图控制器的视图添加到我的父视图控制器中,在这种特殊情况下,您将在父 VC 中正确调用方向更改委托方法,但在随后的您已将其视图添加到父 VC 的视图控制器

我曾经在我的应用程序窗口中添加了一个基本视图控制器,其中基本控制器有一个 ScrollView ,后来我将四个视图控制器的子视图添加到滚动视图。

在此处输入图像描述

  • (void)viewDidLoad {

    DNAppDelegate *appDelegate = (DNAppDelegate*)[UIApplication sharedApplication].delegate;
    
    CGRect viewCustormFrame = appDelegate.viewCustomTabBar.frame;
    viewCustormFrame.origin.y = self.view.frame.size.height-35;
    
    if(UIInterfaceOrientationIsPortrait([UIApplication sharedApplication].statusBarOrientation)) {
        viewCustormFrame.size.width = self.view.frame.size.width;
    }
    else {
        viewCustormFrame.size.width = self.view.frame.size.width;
    }
    
    [self.view addSubview:appDelegate.viewCustomTabBar];
    appDelegate.viewCustomTabBar.frame = viewCustormFrame;
    
    [srclViewMainContent addSubview:appDelegate.homeController.view];
    [srclViewMainContent addSubview:appDelegate.newsListController.view];
    [srclViewMainContent addSubview:appDelegate.columnController.view];
    [srclViewMainContent addSubview:appDelegate.whatsOnController.view];
    
    currentVisisbleController = appDelegate.homeController;
    
    [self resetAllSizes];
    [super viewDidLoad];
    

    }

在上述情况下,虽然我在基本 VC 中调用了所有方向委托方法,但在其他四个 VC 中没有调用 .. 所以我不得不调整类似的东西

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
     DNAppDelegate *appDelegate = (DNAppDelegate*)[UIApplication sharedApplication].delegate;
    [appDelegate.homeController shouldAutorotateToInterfaceOrientation:interfaceOrientation];
    [appDelegate.newsListController shouldAutorotateToInterfaceOrientation:interfaceOrientation];
    [appDelegate.columnController shouldAutorotateToInterfaceOrientation:interfaceOrientation];
    [appDelegate.whatsOnController shouldAutorotateToInterfaceOrientation:interfaceOrientation];
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
    DNAppDelegate *appDelegate = (DNAppDelegate*)[UIApplication sharedApplication].delegate;

    currentPageOffset = srclViewMainContent.contentOffset.x/srclViewMainContent.frame.size.width;
    [appDelegate.homeController willRotateToInterfaceOrientation:toInterfaceOrientation duration:(NSTimeInterval)duration];
    [appDelegate.newsListController willRotateToInterfaceOrientation:toInterfaceOrientation duration:(NSTimeInterval)duration];
    [appDelegate.columnController willRotateToInterfaceOrientation:toInterfaceOrientation duration:(NSTimeInterval)duration];
    [appDelegate.whatsOnController willRotateToInterfaceOrientation:toInterfaceOrientation duration:(NSTimeInterval)duration];
}

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {

    DNAppDelegate *appDelegate = (DNAppDelegate*)[UIApplication sharedApplication].delegate;
    [self resetAllSizes];
    CGRect visibleRect = CGRectMake(currentPageOffset*srclViewMainContent.frame.size.width, 0, srclViewMainContent.frame.size.width, srclViewMainContent.frame.size.height);
    [srclViewMainContent scrollRectToVisible:visibleRect animated:NO];

    [appDelegate.homeController didRotateFromInterfaceOrientation:fromInterfaceOrientation];
    [appDelegate.newsListController didRotateFromInterfaceOrientation:fromInterfaceOrientation];
    [appDelegate.columnController didRotateFromInterfaceOrientation:fromInterfaceOrientation];
    [appDelegate.whatsOnController didRotateFromInterfaceOrientation:fromInterfaceOrientation];

}

即从Base VC 在各自的VC 上调用这些委托方法。我必须这样做,因为我的应用程序已经完全构建,后来我不得不更改架构以允许在各种视图之间滚动,但我已经通过使用四个视图控制器实现了这些视图。

简而言之,任何直接添加到窗口的 VC(也包括导航控制器、选项卡栏控制器、拆分视图控制器)都会将这些方向更改委托方法传播给后续 VC,但视图控制器不会将这些委托方法传递给即将到来的 VC

我希望这能给你一些见解。以防万一您遇到任何好的解决方案,请发布作为答案并与我们所有人分享。

于 2012-05-11T04:24:31.800 回答