我有一个视图A和一个视图控制器B,当View A退出(设备在Landscape中,在B上查看A覆盖)时,我想将B变换为Portrait(设备保持在Landscape中,所以B应该在Landscape之前变换,但是我已经修复了B的框架,所以如果B出现在Landscape中,屏幕的一部分应该是黑暗的,不负责任的 . 但是我在屏幕底部得到了一个不负责任的黑色区域 . 视图B在此屏幕的较小窗口中显示,我可以滚动它 . 我的转换代码如下:
CGFloat r = 1.5 * M_PI;
CGAffineTransform t;
t = CGAffineTransformMakeRotation( r );
UIApplication *application = [ UIApplication sharedApplication ];
self.view.frame = frame;
self.view.center = CGPointMake(frame.origin.x + ceil(frame.size.width/2), frame.origin.y + ceil(frame.size.height/2));
self.view.bounds = [[ UIScreen mainScreen ] bounds ];
t = CGAffineTransformTranslate(t, 130, 105);
[self.view setTransform:t];
[ application setStatusBarOrientation: UIDeviceOrientationPortrait animated: YES ];
1 回答
你的代码有点奇怪,我想这不是你的代码源的复制/粘贴:用一个double初始化t,而没有声明它的CGAffineTransform r没有声明框架
对于你的问题,不同点:不要使用UIView的frame属性如果在该视图上应用了转换,UIScreen的边界包含statusBar的20点高度,请改用UIScreen的applicationFrame方法为什么设置中心然后应用翻译?
如果你的viewController是你的rootViewController(所以它的视图是窗口的直接子视图)你可以尝试类似的东西:
如果你的viewController不是你的rootViewController,你必须确实设置一个旋转,但中心依赖于超视图边界