2014-09-08 2 views
0

ipad 응용 프로그램에서 viewcontroller의 배경으로 이미지를 배치하려고합니다. 나는 설정이보기 컨트롤러의 이미지를 배경 이미지로 설정하고 ipad에서 회전 할 때 유지 관리

UIImage *background = [UIImage imageNamed: @"[email protected]~ipad.png"]; 
      UIImageView *imageView = [[UIImageView alloc] initWithImage: background]; 
      imageView.frame = self.view.bounds; 
      [self.view addSubview: imageView]; 
      [self.view sendSubviewToBack:imageView]; 

이 세로 모드에 대해 잘 작동하지만 내가 가로 모드로 회전 할 때 그림이 채워지지 않는 빈 공간이있어 사용. 다른 유사한 게시물을 기반으로 내 생각은 회전 GET의가 변경 될 때 호출되는 새 사진을 가지고 있었고, 난 똑같은 결과이

{ if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { 

     if((self.interfaceOrientation == UIDeviceOrientationLandscapeLeft) || (self.interfaceOrientation == UIDeviceOrientationLandscapeRight)){ 

      UIImage *background = [UIImage imageNamed: @"[email protected]~ipad.png"]; 
      UIImageView *imageView = [[UIImageView alloc] initWithImage: background]; 
      imageView.frame = self.view.bounds; 
      [self.view addSubview: imageView]; 
      [self.view sendSubviewToBack:imageView]; 



     } else if((self.interfaceOrientation == UIDeviceOrientationPortrait) || (self.interfaceOrientation == UIDeviceOrientationPortraitUpsideDown)){ 

      UIImage *background = [UIImage imageNamed: @"[email protected]~ipad.png"]; 
      UIImageView *imageView = [[UIImageView alloc] initWithImage: background]; 
      imageView.frame = self.view.bounds; 
      [self.view addSubview: imageView]; 
      [self.view sendSubviewToBack:imageView]; 
     }} 

을 시도했다. 이 문제를 해결하는 방법에 대한 아이디어는 인정 될 것입니다!

+0

가로에서 세로 또는 가로에서 세로로 장치를 회전 할 때 장치 가로를 세로 또는 세로로 회전하면 – dheeru

+0

입니까? 경우 ((self.interfaceOrientation == UIDeviceOrientationLandscapeLeft) || (self.interfaceOrientation == UIDeviceOrientationLandscapeRight)) {} 다른 경우 ((self.interfaceOrientation == UIDeviceOrientationPortrait) || (self.interfaceOrientation == UIDeviceOrientationPortraitUpsideDown)) {} – dheeru

+0

앱에서 자동 레이아웃을 사용합니까? – rptwsthi

답변

0

뷰의 자동 크기 설정을 확인하고 NSLog보기의 좌표를 확인한 다음 uiimageview의 UIViewContentModeScale 속성에주의하십시오. 스토리 보드에 단순히 이미지 뷰를 추가하면 어떨까요?

0

작업 코드 : 매우 pixled하지 않을 경우

@interface SOViewController(){ 
    UIImageView *imageView; 
} 

@end 

-(void)initialOrientationHandling 
{ 
    //[self.view removeFromSuperview]; 

    if ([[UIDevice currentDevice]orientation] == UIDeviceOrientationLandscapeLeft || 
     [[UIDevice currentDevice]orientation] == UIDeviceOrientationLandscapeRight){ 

     imageView.frame = self.view.bounds; 

     [self.view addSubview: imageView]; 
     [self.view sendSubviewToBack:imageView]; 


    }else if ([[UIDevice currentDevice]orientation] == UIDeviceOrientationPortrait || 
       [[UIDevice currentDevice]orientation] == UIDeviceOrientationPortraitUpsideDown){ 

     imageView.frame = self.view.bounds; 

     [self.view addSubview: imageView]; 
     [self.view sendSubviewToBack:imageView]; 

    } 
    else if([[UIDevice currentDevice]orientation]== UIDeviceOrientationFaceUp){ 
     if(self.view.frame.size.height < 900){ 

     }else{ 

     } 
    } 
} 

-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation 
{ 

    [self initialOrientationHandling]; 
} 

분명히 이미지가 왜곡됩니다. 나는 당신이 다른 회전을 위해 다른 것을 사용할 것을 권합니다.

+0

그래서 한 사진을 설정하고 다른 사진을 설정한다면? 그리고이 뷰의 어느 것도 올바른 메서드를로드하지 못했습니까? –

0

는 SWIFT :

먼저 두 개의 이미지를 생성, 하나는 가로보기의 크기와 세로의 또 다른입니다.

초기화가 viewWillAppear 방법에서는

   var Imgview = UIImageView() 

이미지 뷰를, 그 때 회전 또한 이미지보기 부하를 변경.

 override func viewWillAppear(animated: Bool) { 
    Imgview.frame = self.view.frame 


    Imgview.contentMode = UIViewContentMode.ScaleAspectFill 
    Imgview.clipsToBounds = true 
    view.addSubview(Imgview) 
     // get notification while rotating 

     NSNotificationCenter.defaultCenter().addObserver(self, selector: "rotate", name: UIDeviceOrientationDidChangeNotification, object: nil 
    ) 


     } 

설정 이미지를 회전하는 기능으로, 알림 센터에서 호출됩니다. 이 me.Hope 근무

    func rotate() 
       { 

if(UIDeviceOrientationIsLandscape(UIDevice.currentDevice().orientation)) 
{ 
    Imgview.frame = self.view.frame 
    Imgview.image = UIImage(named: "landscapeSizeimage.png") 

    self.view.sendSubviewToBack(Imgview) 


    } 

    if(UIDeviceOrientationIsPortrait(UIDevice.currentDevice().orientation)) 
{ 
    Imgview.frame = self.view.frame 
    Imgview.image = UIImage(named: "PortraitSizeimage.png") 

    self.view.sendSubviewToBack(Imgview) 


    }} 

는 내가 우리가 당신의 소원으로 이미지 뷰를 제거 할 수 있습니다 더 imageviews 그래서 대신 bringtosubview을 만들 수 있습니다 잘 모릅니다 someone.And을하는 데 도움이됩니다.