iPhone + CGAffineTransFormRotate(pi / 2)+ statusBarHidden:YES + presentModalViewController = 20像素的空白区域

时间:2009-02-19 04:31:17

标签: iphone cocoa-touch core-graphics

我认为标题很具描述性:

我在一个视图上执行所有这三个操作,结果是屏幕左侧有20像素的空白区域(如果持有iPhone是landscapeLeft)。

我尝试通过执行CGAffineTransFormTranslate(转换,-20,0)修复它

只是“滑动”空白下面的视图。

这开始感觉像是一个错误,其他人都有这个问题吗?

澄清一下,我不是在转动任何观点。我正在感知设备的方向:

[[UIDevice currentDevice] orientation]

如果设备(不是界面)处于横向,那么:

[navigationController presentModalViewController:NewView animated:NO]

转换是在显示之前将我的视图(在IB中创建)旋转到横向。

我的转化代码:

    CGRect myFrame = CGRectMake(0, 0, 480, 320);
    CGAffineTransform transform = [[self.myPeriodicTableViewController view] transform];
    transform = CGAffineTransformRotate(transform, degreesToRadians(rotationDirection * 90));
    transform =  CGAffineTransformTranslate(transform, -20, 0);
    [[self.myPeriodicTableViewController view] setFrame: myFrame];
    CGPoint center = CGPointMake(myFrame.size.height/2.0, myFrame.size.width/2.0);
    [[self.myPeriodicTableViewController view] setTransform: transform];
    [[self.myPeriodicTableViewController view] setCenter: center];

3 个答案:

答案 0 :(得分:6)

我想你可能需要重新进入你的中心:

// Set the center point of the view to the center point of the window's content area.      
self.view.center = CGPointMake(160.0, 240.0);

这是我用于横向视图的整个init方法,并且没有问题。只需确保将笔尖设置为正确的尺寸。

// Implement viewDidLoad to do additional setup after loading the view.
- (void)viewDidLoad {
  [super viewDidLoad];

  // Rotate to landscape
  self.view.frame = CGRectMake(0, 0, 480.0, 320.0);
  if ([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeRight) {
    CGAffineTransform transform = self.view.transform;

    // Set the center point of the view to the center point of the window's content area.      
    self.view.center = CGPointMake(160.0, 240.0);

    // Rotate the view 90 degrees around its new center point.
    transform = CGAffineTransformRotate(transform, (M_PI / 2.0));
    self.view.transform = transform;
  }
}

答案 1 :(得分:2)

好的,我明白了。像往常一样,这是超过1个问题的结果。这些问题都发生在我推动模态视图之前:

首先,在我的代码中,我正在调整我的视图:

[self.view setFrame: [[UIScreen mainScreen] applicationFrame]];

隐藏状态栏后,applicationFrame STILL返回320x460 rect(不是320x480)。 不知道为什么,但以下修复了它:

[self.view setFrame: [[UIScreen mainScreen] bounds]];

这得到了我解除的整个屏幕:

Fullscreen UIView with Status bar and Navigation Bar overlay on the top

其次,在同一行代码中,我不是在和正确的viewController交谈。由于我在基于导航的应用程序中,我必须与NavigationController交谈。如果没有,导航栏永远不会收到消息移动到屏幕顶部以覆盖状态栏留下的空间(这导致我的空白区域)。因此,对这一行代码进行了一次修正:

  [[self.navigationController view] setFrame: [[UIScreen mainScreen] bounds]];

最后,在完成所有这些之后,我可以放心地推动我的模态视图。

答案 2 :(得分:0)

这些都不适合我。 DID的工作原理如下: 我在ViewController.h文件中声明了一个(全局)变量

CGRect                  contentRect;

在我的viewDidLoad方法的ViewController.m中,我将它初始化为:

contentRect = self.view.frame;

然后,为了解雇选择器,我使用

  [self dismissModalViewControllerAnimated:YES]; // Or any other command 
  [self.view setFrame:contentRect]; // ta-da! all set back to normal.