-1

我正在学习在 iOS5 上为 iPhone 开发应用程序。我之前没有任何其他版本的经验。我想支持多个方向,最近我一直在寻找。但我还没有找到解决方案。

1)我可以使用导航控制器,它会根据方向变化将视图控制器推入和弹出堆栈。但这意味着我必须将所有内容复制 2 份,一份用于风景,一份用于肖像。

2)我制作了一个新的横向视图控制器。在 potrait 视图控制器的 willRotateToInterfaceOrientation 方法中,我初始化了 landscpe 视图控制器的一个实例并将其设置为 presentViewController。在横向 VC 中,我初始化了一个 potrait 实例并执行相同操作。但我认为这只会占用越来越多的内存,因为这些实例不会像导航控制器那样被“弹出”。(我还没有阅读内存管理指南)

3)有一些关于调整视图大小的事情。我确实很了解这种方法。

请建议通常使用的方法是什么以及为什么。

4

1 回答 1

0

不需要为横向和纵向创建单独的 ViewController。

If suppose You have a button named btnSample.


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
  UIInterfaceOrientation des=self.interfaceOrientation;
  if ((interfaceOrientation==UIInterfaceOrientationPortrait)||(interfaceOrientation==UIInterfaceOrientationPortraitUpsideDown))
    {

//肖像

btnSample.frame=CGRectMake(10,10,100,70);

    }
  else
  {

//景观

btnSample.frame=CGRectMake(200,100,100,70);

  }

}

于 2012-08-13T08:51:37.973 回答