将旋转变换设置为UIView或其图层似乎不起作用?

Ben*_*tto 9 iphone rotation calayer uiview

我试图让我的屏幕中的一个子视图(由一个视图控制器拥有)在设备旋转时旋转.我的视图控制器允许旋转,我正在尝试将90度旋转应用于一个"静止"视图以抵消整体旋转.

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

有什么想法吗?谢谢.

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

nek*_*kno 26

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

阻止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;
        }
    }
Run Code Online (Sandbox Code Playgroud)


Eik*_*iko 5

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

stuckview.transform = CGAffineTransformMakeRotation(M_PI_2); 
Run Code Online (Sandbox Code Playgroud)

应该做的工作。

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