将旋转变换设置为UIView或其图层似乎不起作用? [英] Setting a rotation transformation to a UIView or its layer doesn't seem to work?

查看:90
本文介绍了将旋转变换设置为UIView或其图层似乎不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to have one of the children views in my screen (owned by one view controller) not rotate when the device rotates. My view controller allows rotations as it should, and I'm trying to apply a 90-degree rotation to the one "stationary" view to counteract the overall rotation.

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

Problem is, everything seems to rotate anyways, and the transform doesn't seem to do anything. I've attempted with an affine transform on the view, and with a 3d transform on the layer (below). The method is getting called, but I never see a visual difference.

有什么想法吗?谢谢。

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


推荐答案

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

To help others find this, I'm adding a couple searchable phrases, like:

阻止UIView旋转

阻止UITableView背景从旋转

prevent a UITableView background from rotating

停止UIView旋转

停止UITableView背景旋转

stop a UITableView background rotation

任何方向的完整样本:

- (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;
        }
    }

这篇关于将旋转变换设置为UIView或其图层似乎不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆