代码之家  ›  专栏  ›  技术社区  ›  Zaid Amir

iphone UIView子类未按请求初始化

  •  0
  • Zaid Amir  · 技术社区  · 16 年前

    我对objective-c和iPhone的开发还不熟悉,但到目前为止,一切都进展顺利,直到我试着深入挖掘(不是太深入)。我的问题是,我无法使用不同方向的特定坐标初始化特定UIView子类。

    旋转效果很好,但问题是应用程序初始化的时间。我在考虑为不同的方向提供不同的布局。

    这三个视图是在项目的nib上创建的,并为它们编码和连接插座。

    问题似乎是从viewDidLoad方法生成的。。。目前看起来是这样的:

    -(void)viewDidLoad{
    
        [super viewDidLoad];
        [view1 removeFromSuperview];
        [view2 removeFromSuperview];
        [view3 removeFromSuperview];
    
        UIInterfaceOrientation curOrientation = self.Orientation;
    
        if(curOrientation == UIInterfaceOrientationPortrait)
        {
           view1 = [[XView alloc] initWithFrame:CGRectMake(20,492,728,492)];
           view2 = [[YView alloc] initWithFrame:CGRectMake(384,20,364,472)];
           view3 = [[ZView alloc] initWithFrame:CGRectMake(20,20,364,472)];
    
           [self.view addSubview:view1];
           [self.view addSubview:view2];
           [self.view addSubview:view3];
        }
        else if(curOrientation == UIInterfaceOrientationLandscapeRight)
        {
          //Different coordinates
        }
        else if(curOrientation == UIInterfaceOrientationLandscapeLeft)
        {
         //Different Coodinates
        }
    
        }
    

    我不确定我在这里做错了什么。。。。我需要帮助。。。

    1 回复  |  直到 16 年前
        1
  •  0
  •   Angel G. Olloqui    16 年前

    您的视图是应用程序中加载的第一个视图吗?我发现在某些情况下,在第一次加载时,方向可以标记为UIDeviceOrientationUnknown。