旋转视图从横向到纵向

时间:2012-07-11 15:53:49

标签: ios uiview rotation

我有一个视图A和一个视图控制器B,当视图A出口(设备在横向,视图A覆盖在B上),我想将B变换为纵向(设备保持在横向,所以B应该在横向之前变换,但我已经修复了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 个答案:

答案 0 :(得分:0)

你的代码有点奇怪,我想这不是代码源的复制/粘贴: 你使用double初始化t而使用CGAffineTransform r未声明 框架未声明

针对您的问题,不同点: 如果在该视图上应用了转换,请不要使用UIView的frame属性 UIScreen的边界包含statusBar的20点高度,改用UIScreen的applicationFrame方法 为什么要设置中心然后应用翻译?

如果你的viewController是你的rootViewController(因此它的视图是窗口的直接子视图)你可以尝试类似的东西:

[self.view setTransform:CGAffineTransformIdentity];
[self.view setCenter:CGPointMake(160, 240)];
[self.view setBounds:CGRectMake(0, 0, 320, 460)];

如果你的viewController不是你的rootViewController,你必须确实设置一个旋转,但中心依赖于超视图边界