Setting a rotation transformation to a UIView or its layer doesn#39;t seem to work?(将旋转转换设置为 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 或其图层似乎不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:将旋转转换设置为 UIView 或其图层似乎不起作用?
基础教程推荐
- AdMob 广告未在模拟器中显示 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
