1

出于大约一百个原因,我只需要以编程方式创建这个 UIViewController 子类视图。只有一个,其他所有视图都使用 IB 进行布局。

好吧,现在我完成了使应用程序自动旋转的任务。这在大多数情况下都很好,但我需要帮助理解其中一些布局选项......特定于自动调整大小和对齐

我如何在这里设置它(这将是称为“标题”的对象,所以[header setAutoresizingMask:...]

在此处输入图像描述

还有这个

在此处输入图像描述

而那些作为_mapView

我一直在不断研究可用的选项,但要么没有任何明显的区别,要么我没有设置正确的选项......

    header = [UIButton buttonWithType:UIButtonTypeCustom];
    [header setFrame:CGRectMake(0, 0, self.view.frame.size.width, 170)];

    // this one shoves the header button when in landscape mode to out of view :\
    [header setAutoresizingMask:UIViewAutoresizingFlexibleTopMargin];
    // the header remains left aligned when in landscape mode...
    [header setContentVerticalAlignment:UIControlContentHorizontalAlignmentCenter];


    [header setBackgroundImage:[[UIImage imageNamed:@"header.png"] stretchableImageWithLeftCapWidth:10.0 topCapHeight:0.0] forState:UIControlStateNormal];
    [header setBackgroundImage:[[UIImage imageNamed:@"header.png"] stretchableImageWithLeftCapWidth:10.0 topCapHeight:0.0] forState:UIControlStateHighlighted];

    [header addTarget:self action:@selector(goHome) forControlEvents:UIControlEventTouchUpInside];



    _mapView = [[[SPMapView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)] autorelease];
    [_mapView setDelegate:self];




    [self.view addSubview:_mapView];
    [self.view addSubview:header];
4

1 回答 1

2

第一个:

CGRect newFrame = mainView.frame;
        newFrame.origin = CGPointMake(160, 170);
        newFrame.size = CGSizeMake(768, 170);
        myView.frame = newFrame;
        myView.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleBottomMargin;

对于第二个:

CGRect newFrame = mainView.frame;
            newFrame.origin = CGPointMake(160, 416);
            newFrame.size = CGSizeMake(320, 247);
            myView.frame = newFrame;
            myView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
于 2012-11-21T18:46:48.977 回答