【问题标题】:Xcode Orientation UIViewXcode 定位 UIView
【发布时间】:2011-07-16 03:25:13
【问题描述】:

我想为横向模式使用与纵向模式不同的 UIView,这可能吗?如果可以,我该怎么做?

【问题讨论】:

    标签: objective-c xcode ipad uiview orientation


    【解决方案1】:

    在 .h 文件中取一个全局变量“currentOrientationView”。 当您的设备要从任何界面方向旋转时,它会调用“WillRotateToInterfaceOrientation:”,此方法有一个参数告诉设备将要旋转的界面方向,因此将您的条件放入此方法并设置值"currentOrientationView" 对应的视图为:

    -(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
    if (UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) {
        currentOrientationView=potraitView;
    }else {
        currentOrientationView=landscapeView;;
    }}
    

    【讨论】:

    • 在视图控制器的 .h 文件中取一个“UIView”类型的变量作为 UIView *currentOrientationView;
    【解决方案2】:

    你必须使用方法 shouldAutorotate 来调整界面方向, 在这个方法里面你必须把代码像

    [self.addSubview:newView];

    【讨论】:

    • 抱歉,更改视图不应在 shouldAutorotateToInterfaceOrientation 中进行。
    • 但没有 '.'在 self 和 addSubview 之间?
    【解决方案3】:

    使用 willRotateToInterfaceOrientation 交换意见。对于您想要支持的所有方向,shouldAutorotateToInterfaceOrientation 应该返回 YES。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-03-16
      • 2010-10-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多