【问题标题】:Preferred way to set frame at run time for different orientation在运行时为不同方向设置框架的首选方法
【发布时间】:2014-05-21 07:51:34
【问题描述】:

我的 iOS 应用有两种不同的 UI 规范。
我在以下情况下面临方向更改问题(不支持倒置)。

仅供参考:我正在使用 self.view.frame.size.width 设置 UI 的宽度并识别方向更改我我正在使用UIDeviceOrientationDidChangeNotification

1.将方向更改为横向
2.改变方向倒置(不设置任何框架)
3. 直接将方向更改为纵向(为纵向模式设置框架)

按照这些步骤,我的 UI 框架被放错了位置。
纵向模式的宽度为 568。

请给我一个更好的方法来解决这个问题。

【问题讨论】:

    标签: ios frame screen-orientation uiinterfaceorientation orientation-changes


    【解决方案1】:

    在旋转时更改self.view 框架不是一个好习惯,因为它的boundUIViewController 旋转逻辑处理。

    您可以使用willRotateToInterfaceOrientation:duration:didRotateFromInterfaceOrientation: 委托方法进行手动轮换。

    【讨论】:

    • 我已经尝试过实现这一点,但是需要一些时间来更改帧,因为我在更改帧之前正在执行许多其他计算功能,因此用户可以看到帧正在移动。在 willRotateToInterFaceorientaion 中,帧正在到来错了。但是感谢您的建议。
    • 尝试使用持续时间参数为 frame 设置动画。
    【解决方案2】:

    您正在列出您的设备方向更改,您需要允许 UI 旋转并使用

    收听它
    - (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
        //update your view's subviews
    }
    

    请注意,UIDeviceOrientation 与 UIInterfaceOrientation 不同

    要允许界面旋转,请将其添加到视图控制器,并确保在项目 plist 中,您在“支持的界面方向”键 中支持横向和纵向

    - (BOOL)shouldAutorotate {
        return YES;
    }
    
    - (NSUInteger)supportedInterfaceOrientations {
        return UIInterfaceOrientationMaskAllButUpsideDown;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-04-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多