0

1 방향, 세로 방향 만 지원하도록 하드 코딩 된 애플리케이션이 있습니다. 세로는 프로젝트 설정을 통해 설정됩니다.회전을 지원하지 않는 iOS 앱에서 UIImageView 회전하기

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
     return (interfaceOrientation == UIInterfaceOrientationPortrait); 
} 

이보기 컨트롤러에는보기, 버튼, 라벨 및 기타 표준 iOS 컨트롤이 있습니다. 이 뷰 컨트롤러 내의 모든 컨트롤에서 원하는 동작은 사용자가 iOS 장치를 회전 할 때 응용 프로그램 내의 아무 것도 회전하지 않는다는 것입니다.

위의 모든보기에서 "배경"역할을하는 것은 UIScrollView 내에 포함 된 UIImageView입니다. 이것이 가장 밑의 모습입니다. 사용자는 언제든지 사진 선택기를 시작하는 버튼을 통해이 배경을 변경할 수 있습니다. UIImageView는 UIScrollView 내에 포함되어 있습니다. 왜냐하면 원하는 동작은 핀치가 배경 이미지를 확대/축소 할 수 있도록하기 위해서입니다.

응용 프로그램이 회전을 지원하지 않지만로드 할 때 ImageView의 내용이 항상 올바른 방향으로 향하게하고 싶습니다.

예 : - 지원되는 방향이 UIInterfaceOrientationPortrait 인 것을 명심하십시오. 사용자가 응용 프로그램을 실행하고 iOS 장치를 LandScape 위치로 회전시킵니다. 인물 사진에있는 동안 사용자는 새 배경 이미지를 선택합니다. 의도 된 동작은 선택된 방향이 현재 방향에 따라 & 양상으로 정해질 것입니다.

본질적으로 나는 배경 이미지가 항상 선택 될 때 지구를 향해 "중력"을 갖기를 원합니다. 사용자가 새 이미지를 선택한 후 iOS 장치를 회전하면 배경 이미지가 회전하지 않습니다. 처음에는 이미지를 선택할 때만 올바르게 방향이 지정됩니다.

CGAffineTransformMakeRotation을 사용하여 이미지를 회전 할 수 있지만 핀치를 통한 확대는 이미지 자체의 픽셀이 실제로 방향을 변경하지 않으므로 바람직하지 않은 동작을 보입니다. 나는이 문제에 대해 어떤 간단한 솔루션을 볼 수 없습니다

UIImage * RightLandscapeImage = [[UIImage alloc] initWithCGImage: userSelectedImage.CGImage 
                 scale: 1.0 
                orientation: UIImageOrientationRight]; 

나는 사용자가 이미지의 라인을 따라 뭔가를 선택할 때 실제로 새로운 이미지를 만들어야 할 수도 있습니다 생각하고

... . 아마도 나는 쉽게 뭔가를 간과하고 있습니까?

다음을 입력하십시오. 이것은 필요할 것으로 보이는 코드입니다. 현재 방향 및 시작 방향을 고려합니다.

UIImage * newImage; 
if(startUpOrientation == UIInterfaceOrientationLandscapeRight) 
{ 
    switch (currentOrientation) { 
     case UIInterfaceOrientationLandscapeLeft: 
      newImage = [[UIImage alloc] initWithCGImage: bgImage.CGImage 
                   scale: 1.0 
                  orientation: UIImageOrientationDownMirrored]; 

      [self.backgroundImageView setImage:newImage]; 
      break; 
     case UIInterfaceOrientationLandscapeRight: 
      [self.backgroundImageView setImage:bgImage]; 
      break; 
     case UIInterfaceOrientationPortraitUpsideDown: 
      newImage = [[UIImage alloc] initWithCGImage: bgImage.CGImage 
                scale: 1.0 
              orientation: UIImageOrientationRight]; 

      [self.backgroundImageView setImage:newImage]; 

      break; 
     default: 
      newImage = [[UIImage alloc] initWithCGImage: bgImage.CGImage 
                scale: 1.0 
              orientation: UIImageOrientationLeft]; 
      [self.backgroundImageView setImage:newImage]; 
      break; 
    } 
} 

답변

1

당신은 당신이 코드를 시도 할 수 있습니다 willRotateToInterfaceOrientation

을 회전 할 모든보기에 변환을 적용 할 수 있습니다

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 
    { 
     switch (toInterfaceOrientation) { 
      case UIInterfaceOrientationLandscapeLeft: 
       yourview.transform = CGAffineTransformMakeRotation(M_PI_2); // 90 degress 
       break; 
      case UIInterfaceOrientationLandscapeRight: 
       yourview.transform = CGAffineTransformMakeRotation(M_PI + M_PI_2); // 270 degrees 
       break; 
      case UIInterfaceOrientationPortraitUpsideDown: 
       yourview.transform = CGAffineTransformMakeRotation(M_PI); // 180 degrees 
       break; 
      default: 
       yourview.transform = CGAffineTransformMakeRotation(0.0); 
       break; 
     } 
    } 
+0

감사합니다. 그건 약간 도움이됩니다. 그러나 이상하게도 나는 이것을 처음으로 집어 넣을 수있는 능력을 잃어 버린다. 다시 한 번 확대하면 핀치가 다시 활성화되지만 처음에는 확대되지 않습니다. – ThatOneGuy

+0

나는 당신이 무엇을 의미하는지 모르겠다, 적어도 한번 회전 장치 후에 적당한 줌을 얻었습니까? 그때부터 괜찮습니까? 그렇다면 viewWillAppear에서'[self willRotateToInterfaceOrientation : [UIApplication sharedApplication] .statusBarOrientation duration : 0]'과 같이 뷰를 보여준 직후에 현재 방향으로 transform을 설정하십시오. 도움이되는지 확인하십시오. –

관련 문제