【问题标题】:Is there a way to convert the coordinate system after a change to Landscape Orientation?有没有办法在更改为横向方向后转换坐标系?
【发布时间】:2010-10-28 04:11:17
【问题描述】:

在基于视图的 iPhone OS 应用程序中,我将方向从最初的纵向方向更改为 横向方向 (UIInterfaceOrientationLandscapeRight)。但是现在 x,y 原点 (0,0) 位于 左下 角(而不是通常的左上角),每次我想做一些涉及坐标的事情时,我都必须重新计算以补偿新的坐标系。我还注意到我在新坐标系中的视图有时表现不正常。那么,有没有办法在我切换方向后立即转换坐标系,以便我可以继续认为我的坐标在左上角角有一个原点?

【问题讨论】:

    标签: iphone orientation device


    【解决方案1】:

    如果您按照推荐的方法对主视图应用变换以旋转它:

    UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
    if (orientation == UIInterfaceOrientationLandscapeRight) 
    {
        CGAffineTransform transform = primaryView.transform;
    
        // Use the status bar frame to determine the center point of the window's content area.
        CGRect statusBarFrame = [[UIApplication sharedApplication] statusBarFrame];
        CGRect bounds = CGRectMake(0, 0, statusBarFrame.size.height, statusBarFrame.origin.x);
        CGPoint center = CGPointMake(60.0, bounds.size.height / 2.0);
    
        // Set the center point of the view to the center point of the window's content area.
        primaryView.center = center;
    
        // Rotate the view 90 degrees around its new center point.
        transform = CGAffineTransformRotate(transform, (M_PI / 2.0));
        primaryView.transform = transform;
    }   
    

    那么你添加到这个主视图的任何子视图都应该使用标准坐标系。应用于主视图的变换也负责旋转子视图的坐标。这在我的应用程序中非常适合我。

    【讨论】:

    • 如果坐标是像 CIRectangleFeature 这样的相机视图图片或 Image 中感兴趣区域的 CGPoints。现在,如果图像是横向的并且正在使用 AspectFit 转换为纵向并且需要显示感兴趣的区域。我们如何将指向横向的点转换为纵向版本的应用程序?在我的情况下,我将相机图像点转换为视图坐标,但它们是横向版本
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多