通过编程方式在横向模式下添加视图

时间:2014-02-28 06:53:54

标签: objective-c uiview landscape

我在横向模式下有一个应用程序,现在我在appdelegate中添加一个视图,但它在纵向模式下显示。旋转90度

下面是我在appdelegate中添加的代码

 -(void)addProcessingView{
    UIView*container = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 100)] autorelease];
    container.backgroundColor = [UIColor grayColor];
    UILabel *label = [[[UILabel alloc] initWithFrame:CGRectMake(100, 0, 400, 100)] autorelease];

  [container addSubview:label];
   UIActivityIndicatorView *active = [[[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0, 0, 100 , 100)] autorelease];
  [container addSubview:active];
  container.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;
  [self.window addSubview:container];
  container.center = self.window.center;
}

见图片

enter image description here

1 个答案:

答案 0 :(得分:0)

我认为您必须更改视图的帧大小。将以下行替换为您的代码。它将解决您的问题。

 UIView*container = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 500)] autorelease];
相关问题