为什么我的UIView在UIViewController的子视图中没有正确调整大小?

时间:2009-09-08 01:42:32

标签: iphone uiview uiviewcontroller

我有一个包含子视图和UIToolbar的UIViewController。我正在尝试添加另一个包含MKMapView的UIViewController作为子视图,但它没有正确调整大小,因此,地图与工具栏重叠。我做错了什么?

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    [DebugLogger writeLog:@"Initializing RootViewController"];
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        // Custom initialization
        self.title = @"Root View";

        switchableView.autoresizesSubviews = YES;
        switchableView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;
        switchableView.userInteractionEnabled = YES;

    }
    return self;
}

- (void)viewDidLoad {
    [DebugLogger writeLog:@"Calling viewDidLoad in RootViewController"];
    [super viewDidLoad];

    self.mapView = [[[MapViewController alloc] initWithNibName:@"MapView" bundle:nil] autorelease];

    [self.mapView.view setFrame:switchableView.frame];

    [switchableView addSubview:self.mapView.view];
}

1 个答案:

答案 0 :(得分:2)

而不是:

switchableView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;

试试这个:

switchableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

另外,尝试将mapView.view的autoresizingMask设置为同样的东西。