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

查看:13
本文介绍了将旋转转换设置为 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.

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

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 旋转

prevent a UIView from rotating

防止 UITableView 背景旋转

prevent a UITableView background from rotating

停止 UIView 旋转

stop a UIView rotation

停止 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天全站免登陆