developer tip

가로 모드의 iPhone 앱, 2008 시스템

optionbox 2020. 8. 27. 07:42
반응형

가로 모드의 iPhone 앱, 2008 시스템


이 질문은 2008 년의 질문이며 지금은 역사적인 관심사 일뿐입니다.


기기의 위치에 관계없이 처음부터 가로 모드로 실행되는 iPhone 애플리케이션을 만드는 가장 좋은 방법은 무엇입니까?

프로그래밍 방식과 인터페이스 빌더 사용 모두.


역사적인 대답 만. 매우 오래되었습니다.

이 답변은 이제 매우 오래되었습니다.

이 대답은 단지 역사적인 호기심 일뿐 입니다.


신나는 소식! 아래 Andrew가 발견 한 것처럼이 문제는 4.0 이상에서 Apple에 의해 수정되었습니다.

더 이상 모든 뷰에서 뷰의 크기를 강요 할 필요가없는 것처럼 보이며 "처음에만 작업"하는 풍경의 특정 심각한 문제가 해결되었습니다.

2011 년 4 월 현재 4.0 이하의 것은 테스트하거나 빌드 할 수 없으므로이 질문은 순전히 역사적인 호기심입니다. 오랫동안 개발자에게 얼마나 많은 문제를 일으켰는지 놀랍습니다!


여기에 원래의 토론과 해결책이 있습니다. 이러한 시스템은 작동하지 않기 때문에 지금은 전혀 관련이 없습니다.


이 작업을 완전히 수행하는 것은 매우 어렵습니다. 최소 세 가지 문제 / 버그가 발생합니다.

이 .. 인터페이스 빌더 조경 디자인 시도

특히 " 모든 곳에서 shouldAutorotateToInterfaceOrientation을 적절하게 사용해야합니다"라는 문구 는 모든 곳에서 모든 전체 화면보기를 의미합니다.

이 악몽에 도움이되기를 바랍니다!

여기에 당면한 추가로 잘 알려진 문제에 대한 중요한 알림 : 하나 이상의 보기 (모든 가로) 간에 전환하려는 경우 간단하게 작동하지 않습니다 . 이것을 기억하는 것이 중요합니다. 그렇지 않으면 문제에 며칠을 낭비하게됩니다. 말 그대로 불가능합니다. iOS 플랫폼에서 가장 크고 알려진 버그입니다. 하드웨어가로드하는 두 번째보기를 가로로 만들 수있는 방법은 말 그대로 없습니다. 성가 시지만 간단한 해결 방법과 수행해야 할 작업은 아무것도하지 않고 뷰간에 전환 할 수있는 간단한 마스터 UIViewController를 사용하는 것입니다.

즉, iOS에서 주요 버그로 인해 :

[window addSubview:happyThing.view];
[window makeKeyAndVisible];

한 번만 할 수 있습니다 . 나중에 happyThing.view를 제거하고 대신 newThing.view에 넣으려고하면 작동하지 않습니다. 그게 전부입니다. 기계는보기를 가로로 회전하지 않습니다. 속임수를 고칠 수는 없습니다. 심지어 Apple도 작동하지 않습니다. 채택해야하는 해결 방법은 단순히 거기에 있고 다양한 뷰 (happyThing, newThing 등)를 보유하는 전체 UIViewController를 갖는 것입니다. 도움이 되었기를 바랍니다.


Apple Dev 사이트에서 :

애플리케이션을 가로 모드에서 시작하여 상태 표시 줄이 즉시 적절한 위치에 있도록하려면 Info.plist 파일을 편집하여 적절한 값 (UIInterfaceOrientationLandscapeRight 또는 UIInterfaceOrientationLandscapeLeft)을 가진 UIInterfaceOrientation 키를 추가합니다 (Listing 2 참조).

목록 2 : 가로 모드에서 애플리케이션 시작

<key>UIInterfaceOrientation</key>
<string>UIInterfaceOrientationLandscapeRight</string>

직접 테스트 한 후 모든 게시물의 요약 및 통합 아래에서 4.x, 5.x에 대한 업데이트를 확인하십시오.

3.2부터는 코드에서 실행중인 애플리케이션의 방향을 변경할 수 없습니다.

그러나 그렇게하는 것이 간단하지는 않지만 고정 된 방향으로 응용 프로그램을 시작할 수 있습니다.

이 조리법으로 시도하십시오.

  1. 파일 UISupportedInterfaceOrientations에서 방향 설정Info.plist
  2. 창에서 480x320 "기본보기 컨트롤러"를 정의합니다. 다른 모든보기는 해당보기에 하위보기로 추가됩니다.
  3. 모든 뷰 컨트롤러에서 shouldAutorotateToInterfaceOrientation:메서드를 설정합니다 (물론 plist에서 정의한 것과 동일한 값을 반환하기 위해)
  4. 모든 뷰 컨트롤러에서 배경 뷰를 설정하십시오.

    self.view.frame = CGRectMake(0, 0, 480, 320)

    viewDidLoad방법.

업데이트 (iOS 4.x, 5.x) : Apple iOS 앱 프로그래밍 가이드의 "고급 앱 트릭"장에 "가로 모드로 실행"단락이 있습니다.

참조 :


먼저 info.plist에서 설정했습니다.

<key>UIInterfaceOrientation</key>
<string>UIInterfaceOrientationLandscapeRight</string>

그런 다음이 코드를 applicationDidFinishLaunching에 넣습니다.

CGAffineTransform rotate = CGAffineTransformMakeRotation(1.57079633);
[window setTransform:rotate];

CGRect contentRect = CGRectMake(0, 0, 480, 320); 
window.bounds = contentRect; 
[window setCenter:CGPointMake(160.0f, 240.0f)]; 

이렇게하면 가로 모드에서 Interface Builder의 뷰에서 작업 할 수 있습니다.


sasb 및 michaelpryor의 대답이 올바른 것처럼 보이지만 작동하지 않으면 다음 대안을 시도하십시오.

- (void)applicationDidFinishLaunchingUIApplication *)application {
    application.statusBarOrientation = UIInterfaceOrientationLandscapeRight;
}

또는 이거 :

[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];

또는 이거 :

[application setStatusBarOrientation: UIInterfaceOrientationLandscapeRight animated:NO];

window makeKeyAndVisible;먼저 전화해야 할 수도 있습니다 .

몇 가지 링크 : 가로 모드에서 개발 , iPhone SDK : 가로 모드 만 강제하는 방법은 무엇입니까?

@Robert : iPhone SDK, NDA 및 Stack Overflow 를 참조하십시오 .


I'm surprised no one has come up with this answer yet:

In all my tests when a dismissing a modal view controller the parent view controller's preferred orientation set in shouldAutorotateToInterfaceOrientation is honored even when part of a UINavigationController. So the solution to this is simple:

Create a dummy UIViewController with a UIImageView for a background. Set the image to the default.png image your app uses on startup.

When viewWillAppear gets called in your root view controller, just present the dummy view controller without animation.

when viewDidAppear gets called in your dummy view controller, dismiss the view controller with a nice cross dissolve animation.

Not only does this work, but it looks good! BTW, just for clarification i do the root view controller's viewWillAppear like this:

- (void)viewWillAppear:(BOOL)animated
{
 if ( dummy != nil ) {
  [dummy setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
  [self presentModalViewController:dummy animated:NO];
  [dummy release];
  dummy = nil;
 }
...
}

The latest iPhone OS Programming Guide has a full section on this, with sample code. I am sure this is a recent addition, so maybe you missed it. It explains all the conditions you have to comply with; basically...

  • set the Info.plist properties (this changes the position of the status bar, but not the view)
  • rotate your view manually around its center, on either your UIViewController viewDidLoad: method or your applicationDidFinishLaunching: method or implement auto rotation ("Autoresizing behaviors", page 124)

Look for "Launching in Landscape Mode", page 102.


See this answer: Landscape Mode ONLY for iPhone or iPad

  1. add orientation to plist
  2. shouldAutorotateToInterfaceOrientation = YES in all files

Although if you're using mixed modes, you might be better off with

[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];

참고URL : https://stackoverflow.com/questions/402/iphone-app-in-landscape-mode-2008-systems

반응형