2017-01-13 8 views
0

이전 iOS 앱의 일부 코드 + xib 레이아웃을 현재 앱과 병합 중입니다.xib 레이아웃을 확장하여 화면 채우기

모두 iPhone 5/6의 레이아웃과 별개입니다. 원래 앱은 해당 화면에 맞게 확장됩니다. 그러나 현재 앱의 새 버튼에서 시작된 이전 앱에서보기 컨트롤러의 하위 집합 만 사용하고 있습니다.

내가보고있는 것은 iPhone 4 크기 레이아웃이 예를 들어 화면 왼쪽 상단을 차지하는 것입니다. 아이폰 6, 이전 코드에서보기 컨트롤러가로드 될 때.

여러 가지 시도를했습니다. 약간의 차이를 만든 한 가지 기존 응용 프로그램의되는 SplashScreen의 코드를 찾고 있었어요 :

- (void)loadView 
{ 
    [[[NSBundle mainBundle] loadNibNamed:@"HomeScreenViewController" owner:self options:nil] objectAtIndex:0]; 
    self.view.autoresizesSubviews = YES; 
    [self.view setTranslatesAutoresizingMaskIntoConstraints:NO]; 
    self.view.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; 

    UIImage* backgroundImage = [UIImage imageNamed:@"Default-no-logo.png"]; 
    self.view.backgroundColor = [UIColor colorWithPatternImage:backgroundImage]; 

    CGRect appFrame = [[UIScreen mainScreen] applicationFrame]; 

    [self.view setFrame:appFrame]; 
} 
:
// Implement loadView to create a view hierarchy programmatically, without using a nib. 
- (void)loadView { 

    //Init the View 
    CGRect appFrame = [[UIScreen mainScreen] applicationFrame]; 
    UIView *view = [[UIView alloc] initWithFrame:appFrame]; 
    view.autoresizingMask = UIViewAutoresizingFlexibleHeight |UIViewAutoresizingFlexibleWidth; 
    self.view = view; 
    [view release]; 

    NSString *splashImageName = nil; 

    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) 
     splashImageName = @"iPadDefault2.png"; 
    else 
     splashImageName = @"Default.png"; 

    mSplashImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:splashImageName]]; 
    [self.view addSubview:mSplashImageView]; 

} 

그래서 나는 새로운 응용 프로그램에서 실행 뷰입니다 HomeScreenViewController에 다음을 추가

이제 iPhone 6의 공간을 채우기 위해 배경 이미지가 바뀌었지만 인터페이스는 왼쪽 상단의 위치와 크기가 동일합니다.

나는 사용자 정의 UIView를 만드는 UIView added programmatically full screen wrong size과 같은 대답을 보았지만 내 상황에는 도움이되지 않습니다.

편집 :

NSString *splashImageName = nil; 

splashImageName = @"Default-no-logo.png"; 

mSplashImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:splashImageName]]; 

mSplashImageView.contentMode = UIViewContentModeScaleAspectFit; 

[mSplashImageView setFrame:appFrame]; 

[self.view addSubview:mSplashImageView]; 

내가 이미지 쇼 전체 화면을 얻을 : 나는 loadView 방법을 변경하는 경우

. 그러나 사용자 지정 UIView 함께 이렇게 작동하지 않습니다. autoresizingMask을 존중하고 더 큰 디스플레이로 성장하기 위해 UIView를 얻으려면 어떻게해야합니까? 나는 아이폰 6, 다양한 장소에서 디버그 포인트를 설정 한

은 항상 높이가 대답 안 667

+0

확인 콘센트 –

+0

기본적으로 제거와 출구의 새 인스턴스를 만들하시기 바랍니다 콘센트 문제는 –

답변

0

이 말한다, 그래서 나는 등으로 표시하지 않을 것이다, 그러나 이것은이다 이 상황에서 실제로 작동하는 해결 방법은 (나는 거의 2 일 동안 여러 가지 방법으로 시도했다.).

기본적으로 화면 비율을 유지하면서 화면을 채우기 위해 AffineTransform을 사용하여보기를 확대하고 있습니다.

AspectFillViewController.h :

#import <UIKit/UIKit.h> 
@interface AspectFillViewController : UIViewController 
@end 

#import "AspectFillViewController.h" 
@interface AspectFillViewController() 
@end 

AspectFillViewController.m :

@implementation AspectFillViewController 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view. 

    CGRect appFrame = [[UIScreen mainScreen] applicationFrame]; 

    self.view.frame = appFrame; 

    // Default size: 320 x 460 - this is the size of the xib layout 
    int defaultWidth = 320; 
    int defaultHeight = 460; 

    // Hacky resizing code 
    if (appFrame.size.width > defaultWidth || appFrame.size.height > defaultHeight) 
    { 
     CGFloat scaleX = appFrame.size.width/defaultWidth; 
     CGFloat scaleY = appFrame.size.height/defaultHeight; 
     CGFloat scale = scaleY > scaleX ? scaleX : scaleY; 
     self.view.transform = CGAffineTransformMakeScale(scale, scale); 

     // This does not work (hence not an ideal solution) 
     self.view.center = CGPointMake(appFrame.size.width/2, appFrame.size.height/2); 

    } 
} 
당신이 XIB 파일에서 생성