Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/111.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
Ios 旋转后,交换UIView坐标,但UIWindow';他们不是吗?_Ios_Uiview_Rotation_Uiwindow - Fatal编程技术网

Ios 旋转后,交换UIView坐标,但UIWindow';他们不是吗?

Ios 旋转后,交换UIView坐标,但UIWindow';他们不是吗?,ios,uiview,rotation,uiwindow,Ios,Uiview,Rotation,Uiwindow,使用Xcode 4.2.1 iPad iOS 5.0.1,创建一个新的“单视图”iPad项目。在控制器中,添加: - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return YES; } - (void) dumpView: (UIView *) view { CGRect frame = view.frame ; CGRect

使用Xcode 4.2.1 iPad iOS 5.0.1,创建一个新的“单视图”iPad项目。在控制器中,添加:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return YES;
}

- (void) dumpView: (UIView *) view {
    CGRect frame = view.frame ;
    CGRect bounds = view.bounds ;
    CGPoint center = view.center ;

    NSLog(@"view [%@]:%d frame=%@ bounds=%@ center=%@"
          ,   NSStringFromClass(view.class)
          ,   [view hash]
          ,   NSStringFromCGRect(frame)
          ,   NSStringFromCGRect(bounds)
          ,   NSStringFromCGPoint(center)) ;
}

- (void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation) fromInterfaceOrientation {

    NSLog(@"INViewController.didRotateFromInterfaceOrientation: %d to %d", fromInterfaceOrientation, self.interfaceOrientation) ;
    [self dumpView: self.view] ;
    [self dumpView: self.view.superview] ;
}
运行它,旋转设备,您将获得:

INViewController.didRotateFromInterfaceOrientation: 2 to 4
view [UIView]   bounds={{0, 0}, {1024, 748}} center={394, 512}
view [UIWindow] bounds={{0, 0}, {768, 1024}} center={384, 512}
换句话说,UIView的坐标按预期“交换到横向”,但其父UIWindow仍声称处于纵向模式

此外,UIView的大小似乎有点错误:y坐标应该是20,而y坐标是0


有人知道这意味着什么吗?

UIWindow的坐标系始终是纵向的。它通过设置其rootViewController的视图的变换来应用旋转。例如,我使用单视图模板创建了一个测试应用程序并运行了它。在纵向方向:

(gdb) po [[(id)UIApp keyWindow] recursiveDescription]
<UIWindow: 0x9626a90; frame = (0 0; 768 1024); layer = <UIWindowLayer: 0x9626b80>>
   | <UIView: 0x96290e0; frame = (0 20; 768 1004); autoresize = W+H; layer = <CALayer: 0x96286a0>>

有道理。非常感谢。顺便说一句,谢谢你告诉我gdb实际上可以交互使用:-)@rob,除了UIView.frame的ref docs说:警告如果transform属性不是identity transform,那么这个属性的值是未定义的,因此应该忽略。你能详细说明一下吗?假设我想为旋转视图的帧设置动画,将其作为覆盖滑动。如果
transform
不是标识,我不依赖代码中的
frame
。但是,
frame
方法似乎总是返回
[self-convertRect:self.bounds-to-view:self.superview]
,因此在调试时非常有用。
(gdb) po [[(id)UIApp keyWindow] recursiveDescription]
<UIWindow: 0x9626a90; frame = (0 0; 768 1024); layer = <UIWindowLayer: 0x9626b80>>
   | <UIView: 0x96290e0; frame = (0 0; 748 1024); transform = [0, 1, -1, 0, 0, 0]; autoresize = W+H; layer = <CALayer: 0x96286a0>>
(gdb) po [[(id)UIApp keyWindow] recursiveDescription]
<UIWindow: 0x9626a90; frame = (0 0; 768 1024); layer = <UIWindowLayer: 0x9626b80>>
   | <UIView: 0x96290e0; frame = (20 0; 748 1024); transform = [0, -1, 1, 0, 0, 0]; autoresize = W+H; layer = <CALayer: 0x96286a0>>
(gdb) p (CGRect)[[[[(id)UIApp keyWindow] subviews] lastObject] frame]
$2 = {
  origin = {
    x = 0, 
    y = 20
  }, 
  size = {
    width = 768, 
    height = 1004
  }
}