2012-09-30 4 views
0

이전에 실제로 사용 된 빌더가 너무 많아서 내보기에서 내 객체 크기를 조정할 때 문제가 발생했습니다.코드에서 크기 조정보기가 작동하지 않습니다.

저는 홈 화면이 내 선택이 아닌 코드로 작성되었으며 ip 크기로 크기를 조정합니다. 문제는 크기 조정과 관련하여 아무런 문제가없는 것입니다.

- (void)loadView 
{ 
// Create the main view 
UIView *mainView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
mainView.backgroundColor = [UIColor blackColor]; 



// Add textured background 
UIImageView *textureBg = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320.0f, 580.0f)]; 
textureBg.image = [UIImage imageNamed:@"BgTexture"]; 
[mainView addSubview:textureBg]; 

//////////////////////////////////Code addded resize view///////////////////////////////////////// 
[textureBg setAutoresizingMask:(UIViewAutoresizingFlexibleHeight| UIViewAutoresizingFlexibleWidth)]; 





// Add clipboard background 
UIImageView *clipBg = [[UIImageView alloc] initWithFrame:CGRectMake(7.0f, 6.0f, 305.0f, 465.0f)]; 
clipBg.image = [UIImage imageNamed:@"BgHomeNew2"]; 
clipBg.userInteractionEnabled = YES; 

////////////////////////////////////Code addded resize view///////////////////////////////////////// 
[clipBg setAutoresizingMask:(UIViewAutoresizingFlexibleBottomMargin| UIViewAutoresizingFlexibleWidth)]; 




// Add about button to clipbg 
UIButton *aboutButton = [UIButton buttonWithType:UIButtonTypeCustom]; 
aboutButton.frame = CGRectMake(240.0f, 90.0f, 31.0f, 33.0f); 
[aboutButton setImage:[UIImage imageNamed:@"LabelButton"] forState:UIControlStateNormal]; 
[aboutButton addTarget:self action:@selector(aboutButtonPressed:) forControlEvents:UIControlEventTouchUpInside]; 
[clipBg addSubview:aboutButton]; 

    // Create array of arrays to hold button image names and their targets 
NSMutableArray *buttonsArray = [[NSMutableArray alloc] initWithObjects: 
            [NSArray arrayWithObjects: 
             @"BtnNewCert", @"newCertButtonPressed:", nil], 
            [NSArray arrayWithObjects: 
             @"BtnContractorDetails", @"contractorDetailsButtonPressed:", nil], 
            [NSArray arrayWithObjects: 
             @"BtnSavedCerts", @"savedCertsButtonPressed:", nil], 
            nil]; 

// Iterate over the array and create the buttons 
CGPoint buttonOrigin = CGPointMake(16.0f, 157.0f); 
for (NSArray *buttonArray in buttonsArray) { 
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; 
    button.frame = CGRectMake(buttonOrigin.x, buttonOrigin.y, 273.0f, 88.0f); 
    [button setBackgroundImage:[UIImage imageNamed:[buttonArray objectAtIndex:0]] forState:UIControlStateNormal]; 
    [button addTarget:self action:NSSelectorFromString([buttonArray objectAtIndex:1]) forControlEvents:UIControlEventTouchUpInside]; 
    //[button addTarget:self action:@selector(playButtonSound) forControlEvents:UIControlEventTouchUpInside]; 
    buttonOrigin.y += 98.0f; 
    [clipBg addSubview:button]; 
} 

[mainView addSubview:clipBg]; 

// Add more apps button 
DebugLog(@"Adding more apps button"); 
UIButton *moreAppsButton = [UIButton buttonWithType:UIButtonTypeCustom]; 
moreAppsButton.frame = CGRectMake(25.0f, 12.0f, 75.0f, 24.0f); 
[moreAppsButton addTarget:self action:@selector(moreAppsButtonPressed:) forControlEvents:UIControlEventTouchUpInside]; 
[moreAppsButton setImage:[UIImage imageNamed:@"BtnMoreApps"] forState:UIControlStateNormal]; 
[mainView addSubview:moreAppsButton]; 




// Add cabinet for iPhone5 
UIImageView *cabinet = [[UIImageView alloc] initWithFrame:CGRectMake(-2.0f, 445.0f, 324.0f, 128.0f)]; 
cabinet.image = [UIImage imageNamed:@"Cabinet2"]; 
[mainView addSubview:cabinet]; 
[mainView bringSubviewToFront:cabinet]; 







self.view = mainView; 
+0

[this] (http://stackoverflow.com/questions/5689753/how-does-ios-determine-to-apply-the-autoresizing-masks-if-launched-on-ipad)를 확인해주십시오. 그건 의심의 여지가 없어야합니다. – Shashikanth

+0

'self.view'를'mainView'로 지정하는 부분이 보이지 않습니다. 나머지 방법을 보여줄 수 있습니까? –

+0

@ Carl이 더 많은 코드를 추가했습니다 – JSA986

답변

1

이것은 예상되는 동작입니다. 크기를 조정할 필요가 없습니다. 화면 경계를 사용하여 기본보기를 초기화합니다. 따라서 iPhone 또는 iPad에 상관없이 장치의 화면 크기를 직접 가져오고 회전이 있거나 기본보기의 프레임을 프로그래밍 방식으로 변경할 때까지 크기가 조정되지 않습니다. iOS가 textureBg을 iPhone에서 320 포인트로 만들고 iPad에있는 경우 연장하도록 할 수있는 방법이 없습니다.
화면 크기에 맞게 조정해야하는보기의 프레임을 계산해야합니다. 그리고 320과 같이 고정 된 크기는 사용하지 말아야하며 self.view.bounds.size.width과 같은 것을 선호합니다. iPad에 적응해야하는 상황에서 시간을 절약 할 수 있습니다.

+0

그 말이 맞습니다, 고맙습니다. – JSA986

관련 문제