Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.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
Uiview 旋转时视图移动到不合适的位置_Uiview_Uiviewcontroller_Uipickerview - Fatal编程技术网

Uiview 旋转时视图移动到不合适的位置

Uiview 旋转时视图移动到不合适的位置,uiview,uiviewcontroller,uipickerview,Uiview,Uiviewcontroller,Uipickerview,我创建了一个UIViewController(基于),以便在设备旋转时在两个视图之间切换。每个视图都是针对特定方向的“专用”视图 它使用UIDeviceOrientationIDChangeNotification通知切换视图: -(void) deviceDidRotate: (NSNotification *) aNotification{ UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation

我创建了一个UIViewController(基于),以便在设备旋转时在两个视图之间切换。每个视图都是针对特定方向的“专用”视图

它使用UIDeviceOrientationIDChangeNotification通知切换视图:

-(void) deviceDidRotate: (NSNotification *) aNotification{

    UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];

    NSLog(@"Device rotated to %d!", orientation);

    if ((orientation == UIDeviceOrientationPortrait) ||
        (orientation == UIDeviceOrientationPortraitUpsideDown)) {
        [self displayView:self.portraitViewController.view];
    }else if ((orientation == UIDeviceOrientationLandscapeLeft) ||
               (orientation == UIDeviceOrientationLandscapeRight)) {
        [self displayView:self.landscapeViewController.view];
    }

}
还有一些作品。当我旋转到横向,然后再回到纵向时,问题就出现了。返回到纵向视图时,子视图不会显示在正确的位置,特别是UIPickerView:

第一次画像

旋转到横向

返回到纵向视图

如果我重复旋转的过程,事情会变得更糟。我做错了什么

源代码如下:


提前谢谢

要解决偏移量问题,请重写displayView:方法,如下所示

-(无效)显示视图:(UIView*)查看{ self.view=aView; }

然而,旋转是奇怪的。您应该检查这部分代码。 使用UIViewController旋转方法

  • (无效)将旋转接口方向:持续时间:
  • (无效)DIDROATEFROMINTERFACE方向:
而不是-(void)deviceDidRotate:

更简单的是,您将避免这种奇怪的反弹,并且不再需要通知。 阅读苹果的文档,了解我上面指定的方法


希望这有帮助。

好的,我发现了错误。这很简单也很愚蠢:我混合了框架和边界


在displayView:code中,我正在将子视图的框架设置为父视图的框架,此时它应该是父视图的边界。

我尝试按照您的建议更改displayView:code,但没有成功。无论如何,谢谢你。