Nice programing

iPhone 6 Plus 홈 화면에서 가로 방향으로 세로 방향으로 시작하면 방향이 잘못됨

nicepro 2020. 12. 7. 20:39
반응형

iPhone 6 Plus 홈 화면에서 가로 방향으로 세로 방향으로 시작하면 방향이 잘못됨


이 질문의 실제 제목은 내가 맞출 수있는 것보다 깁니다.

루트 뷰 컨트롤러가 세로 방향 만 지원하지만 그렇지 않으면 홈 화면이 가로 방향 인 동안 iPhone 6 Plus에서 가로 방향을 지원하는 앱을 실행하면 앱의 창이 가로 방향이지만 기기는 림보 상태가됩니다. 세로 방향으로.

요약하면 다음과 같습니다.

다음과 같이 표시되어야하는 경우 :

재현 단계 :

  1. iOS 8.0을 실행하는 iPhone 6 Plus.

  2. plist가 세로 방향이 아닌 모든 방향을 지원하는 앱입니다.

  3. 앱의 루트 뷰 컨트롤러는 UITabBarController입니다.

  4. 모든 것, 탭 막대 컨트롤러 및 모든 하위 하위 뷰 컨트롤러 UIInterfaceOrientationMaskPortraitsupportedInterfaceOrientations.

  5. iOS 홈 화면에서 시작합니다.

  6. 가로 방향으로 회전합니다 (iPhone 6 Plus 필요).

  7. 앱을 콜드 실행합니다.

  8. 결과 : 인터페이스 방향이 깨졌습니다.

가로 방향 을 모두 비활성화하는 것 외에는 세로 방향을 적용하는 다른 방법을 생각할 수 없습니다. 웹 브라우저 모달 뷰 컨트롤러에는 가로가 필요합니다.

UITabBarController를 서브 클래 싱하고 supportedInterfaceOrientations를 재정 의하여 세로 전용 마스크를 반환하려고 시도했지만 위의 다른 모든 단계에서도 문제가 해결되지 않았습니다.


다음은 버그를 보여주는 샘플 프로젝트에 대한 링크입니다.



iPhone 6 Plus에서 가로 모드로 앱을 실행할 때 동일한 문제가 발생했습니다.

수정 사항은 프로젝트 설정을 통해 plist에서 가로 지원 인터페이스 방향을 제거하는 것입니다.

가로 방향 제거

앱 대리자에서 application : supportedInterfaceOrientationsForWindow :를 구현합니다.

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
    return UIInterfaceOrientationMaskAllButUpsideDown;
}

분명히 plist의 정보는 앱을 시작할 수있는 방향을 지정하는 것입니다.


의 설정은 나를 위해 작동 statusBarOrientation하는 UIApplication것 같습니다. application:didFinishLaunchingWithOptions:앱 델리게이트 메서드에 배치했습니다 .

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    application.statusBarOrientation = UIInterfaceOrientationPortrait;

    // the rest of the method
}

이는 UITabBarController를 루트 뷰 컨트롤러로 사용할 때 iOS 8의 버그로 보입니다. 해결 방법은 대부분 기본 UIViewController를 루트 뷰 컨트롤러로 사용하는 것입니다. 이 바닐라 뷰 컨트롤러는 탭 바 컨트롤러의 부모 뷰 컨트롤러 역할을합니다 :

///------------------------
/// Portrait-Only Container
///------------------------

@interface PortraitOnlyContainerViewController : UIViewController

@end

@implementation PortraitOnlyContainerViewController

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait;
}

@end

// Elsewhere, in app did finish launching ...

PortraitOnlyContainerViewController *container = nil;

container = [[PortraitOnlyContainerViewController alloc] 
              initWithNibName:nil 
              bundle:nil];

[container addChildViewController:self.tabBarController];
self.tabBarController.view.frame = container.view.bounds;
[container.view addSubview:self.tabBarController.view];
[self.tabBarController didMoveToParentViewController:container];

[self.window setRootViewController:container];

나는 매우 비슷한 문제가 있었다. 비디오 재생을 제외하고 모든 곳에서 세로 모드를 강제하고 싶었습니다.

내가 한 일은 :

1) to force the app orientation to be in portrait in the AppDelegate:

-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
    if ([window.rootViewController.presentedViewController isKindOfClass:[MPMoviePlayerViewController class]])
    {
        return UIInterfaceOrientationMaskAll;
    }
    return UIInterfaceOrientationMaskPortrait;
}

2) launching an empty modal view controller fixed the problem in my case. I launch it in the viewDidLoad of the first view controller that is on the root of my NavigationViewController (the first view controller visible after the application launches):

- (void)showAndHideNamelessViewControllerToFixOrientation {
    UIViewController* viewController = [[UIViewController alloc] init];
    [self presentViewController:viewController animated:NO completion:nil];
    [viewController dismissViewControllerAnimated:NO completion:nil];
}

Please try the following code. Probably this problem caused by size of keywindow on landscape launch.

// in application:didFinishLaunchingWithOptions: ...

self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
[self.window setFrame:[[UIScreen mainScreen] bounds]]; //<- ADD!!

No luck for me the workaround by Jared using a generic container view controller. I've already subclassed tab bar controller with supportedInterfaceOrientations with no luck as well. Regardless of orientation of the 6+ after launch the tab bar's window is reporting frame = (0 0; 736 414)

So far the only workaround I've found is to force the window frame after makeKeyAndVisible

[self.window makeKeyAndVisible]; self.window.frame = CGRectMake(0, 0, MIN(CGRectGetWidth(self.window.frame), CGRectGetHeight(self.window.frame)), MAX(CGRectGetWidth(self.window.frame), CGRectGetHeight(self.window.frame)));


I only want my app to open in landscape mode (and not exhibit the problem you describe above on the iPhone 6 Plus), so I set Landscape (left home button) and Landscape (right home button) as the only orientations allowed in my app's PLIST file. This fixes the orientation problem when my app opens. However, I need my app to support portrait mode for one view only since I display a UIImagePickerController in my app, which Apple requires to be shown in portrait mode on iPhone.

I was able to support portrait for that one view only, while keeping my app opening in landscape mode, by including the following code in AppDelegate:

-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {

    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {

        return UIInterfaceOrientationMaskAllButUpsideDown;

    } else {

        return UIInterfaceOrientationMaskAll;

    }

}

I got same bug on my app, I figured it out with this solution

Firstly it didn't work but after some dig I have to do it on initial controller after splash screen.

Answer is OjbC language let me update it to Swift

override var shouldAutorotate: Bool {
    return true
}

override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
    return .portrait
}

Don't forget that should on the initial view controller.


For myself, I was having the same issue as jaredsinclair, but subclassing a UIViewController with the supportedInterfaceOrientations method was not solving the issue. Instead I did exactly what he did in my appDidFinishLaunching method of my AppDelegate and added my UITabBarController as a child to a normal UIViewController rather than his subclass and it worked!


I'm in the same situation, and doing [self.window setFrame:...] doesn't work for me.

Adding the following at the end of application:didFinishLaunchingWithOptions is the only thing I've found that works. It makes the screen blink and isn't exactly clean and efficient.

I added this at the end of application:didFinishLaunchingWithOptions:

UIViewController *portraitViewController = [[UIViewController alloc] init];
UINavigationController* nc = [[UINavigationController alloc] initWithRootViewController:portraitViewController];
[self.navController presentViewController:nc animated:NO completion:nil];
[self.navController dismissViewControllerAnimated:NO completion:nil];  
[UIViewController attemptRotationToDeviceOrientation];

I had a similar issue is with my app runs both in landscape and portrait with a UITabBarController as root view controller.

Whenever the app was launched when in Landscape mode, the view was incorrect.

All I had to do: - remove rootview controller assignment in the XIB. - Manually add it in once the app is launched:


  • (void)applicationDidFinishLaunching:(UIApplication *)application { application.statusBarHidden = YES;

    [self.window setRootViewController:self.tabBarController];


That fixed the problem.


Just Remove All the items in Supported interface orientation except what you want (i need only Portrait) in info.plist , it will work for me여기에 이미지 설명 입력


just call [application setStatusBarOrientation:UIInterfaceOrientationPortrait animated:NO]; in app delegate method - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

실제로 장치는 이제 시작 후 UIInterfaceOrientationPortrait입니다. inputField를 터치하면 키보드가 세로 레이아웃입니다.

참고 URL : https://stackoverflow.com/questions/26003086/launching-into-portrait-orientation-from-an-iphone-6-plus-home-screen-in-landsca

반응형