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

Setting a rotation transformation to a UIView or its layer doesn#39;t seem to work?(将旋转转换设置为 UIView 或其图层似乎不起作用?)
本文介绍了将旋转转换设置为 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 或其图层似乎不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Pushing UIViewController above UITabBar(将UIView控制器推送到UITabBar上方)
java.lang.IllegalStateException: SimpleTypeImpl should not be created for error type(异常:不应为错误类型创建SimpleTypeImpl)
Android IllegalArgumentException: The tag for fragment_XXX is invalid. Received: layout-sw600dp/fragment_XXX_0(Android IlLegalArgumentException:Fragment_XXX的标签无效。收到:Layout-sw600dp/Fragment_XXX_0)
iOS convert audio sample rate from 16 kHz to 8 kHz(IOS将音频采样率从16 kHz转换为8 kHz)
Enforcing an audio sampling rate in iOS(在iOS中强制音频采样率)
Question about the rotation of X axis on Android(关于Android上X轴旋转的问题)