【问题标题】:Setting a rotation transformation to a UIView or its layer doesn't seem to work?将旋转转换设置为 UIView 或其图层似乎不起作用?
【发布时间】:2011-03-11 07:17:08
【问题描述】:

我试图让我的屏幕中的一个子视图(由一个视图控制器拥有)在设备旋转时旋转。我的视图控制器允许旋转,我正在尝试对一个“固定”视图应用 90 度旋转以抵消整体旋转。

问题是,无论如何,一切似乎都在旋转,而变换似乎没有做任何事情。我尝试在视图上进行仿射变换,并在图层上进行 3d 变换(下图)。该方法被调用,但我从未看到视觉差异。

有什么想法吗?谢谢。

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration
{
    CALayer *layer = stuckview.layer;
    layer.transform = CATransform3DMakeRotation(90, 0, 0, 1);
}    

【问题讨论】:

    标签: iphone uiview rotation calayer


    【解决方案1】:

    你的代码真的执行了吗? (你实现了 shouldAutorotateToInterfaceOrientation: 吗?)

    stuckview.transform = CGAffineTransformMakeRotation(M_PI_2); 
    

    应该做的工作。

    注意:函数采用弧度而不是度数。

    【讨论】:

      【解决方案2】:

      为了帮助其他人找到这个,我添加了几个可搜索的短语,例如:

      防止 UIView 旋转

      防止 UITableView 背景旋转

      停止 UIView 旋转

      停止 UITableView 背景旋转


      任何方向的完整示例:

      - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
          {
              switch (toInterfaceOrientation) {
                  case UIInterfaceOrientationLandscapeLeft:
                      stuckview.transform = CGAffineTransformMakeRotation(M_PI_2); // 90 degress
                      break;
                  case UIInterfaceOrientationLandscapeRight:
                      stuckview.transform = CGAffineTransformMakeRotation(M_PI + M_PI_2); // 270 degrees
                      break;
                  case UIInterfaceOrientationPortraitUpsideDown:
                      stuckview.transform = CGAffineTransformMakeRotation(M_PI); // 180 degrees
                      break;
                  default:
                      stuckview.transform = CGAffineTransformMakeRotation(0.0);
                      break;
              }
          }
      

      【讨论】:

      • 我检查并发现 UIInterfaceOrientationPortraitUpsideDown 在 ios 6 中不起作用。
      • 卡住视图是CALAyer还是UIView?
      • @AdamWaite - 一个 UIView,如名称和描述所示! ;-)
      • 这个答案真的很有帮助!非常感谢!
      • CGAffineTransforms 用于视图而不是图层。所以答案不是问题所在。
      猜你喜欢
      • 1970-01-01
      • 2012-12-25
      • 2012-01-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-27
      • 2020-09-18
      • 1970-01-01
      相关资源
      最近更新 更多