프로그래밍 방식으로 설정하는 방법 방향에서 viewdidload 작동하지 않는
-
23-12-2019 - |
문제
나는 응용 프로그램을 만들었 ipad 에서는 홈 화면이 표시되어야 합니다.그래서 내가 사용 아래 코드에 viewdidload.
[[UIDevice currentDevice] setOrientation:UIDeviceOrientationPortrait];
하지만 그것은 작동하지 않습니다.내가 사용하 ios7xcode5.면 응용 프로그램에서 풍경 모드 shouuld 을 자동으로 설정합니다.하지만 나는 다음과 같다:
하지만 그것은 다음과 같이해야한다:
할 수 있는 어떤 사람이 나에게 도움이 될 이 문제를 해결하기 위해.미리 감사드립니다.
해결책
[[UIDevice currentDevice] setOrientation:UIDeviceOrientationPortrait];
.
이 방법은 더 이상 사용되지 않습니다.이 방법은 더 이상 사용할 수 없습니다.
https://stackoverflow.com/a/12813644/1405008
위의 링크는 UIViewController
의 초상화 전용 모드를 제공하는 방법에 대해 자세히 설명합니다.
NavigationViewController
에 밀어 넣으면이 작업을 수행하십시오.
다른 팁
다음 코드는 탐색 컨트롤러보기를 프로그래밍 방식으로 가로로 가로로 변환하려고합니다.
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.3];
self.navigationController.view.transform = CGAffineTransformIdentity;
self.navigationController.view.transform = CGAffineTransformMakeRotation(M_PI*(90)/180.0);
self.navigationController.view.bounds = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.height, [UIScreen mainScreen].bounds.size.width);
[UIView commitAnimations];
self.view.frame = self.view.frame; //This is necessary
self.wantsFullScreenLayout = YES;
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO];
- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
return (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscapeRight;
}
.
다른 아이디어를 제공하기를 희망합니다.
viewDIDLOAD
에이 코드를 복사하십시오.UIInterfaceOrientation orientation = (UIInterfaceOrientation)[[UIDevice currentDevice] orientation];
if(orientation == UIInterfaceOrientationPortrait)
{
isLandscapeMode = NO;
inLandscapeRight = NO;
inLandscapeLeft = NO;
}
else if(orientation == UIInterfaceOrientationLandscapeRight)
{
isLandscapeMode = YES;
inLandscapeRight = YES;
inLandscapeLeft = NO;
} else if(orientation == UIInterfaceOrientationLandscapeLeft)
{
isLandscapeMode = YES;
inLandscapeRight = NO;
inLandscapeLeft = YES;
}
-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft)
{
isLandscapeMode = YES;
inLandscapeLeft = YES;
inLandscapeRight = NO;
frameForProfile = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height);
}
else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
isLandscapeMode = YES;
inLandscapeLeft = NO;
inLandscapeRight = YES;
frameForProfile = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height);
}
else
{
isLandscapeMode = NO;
inLandscapeLeft = NO;
inLandscapeRight = NO;
}
}
.
귀하의 요구 사항에 따라 BOOL 설정
스크린 샷에서 앱이 탭베이스임을 알 수 있습니다.며칠 전에 나는 같은 문제에 직면했다.나는 그것을 해결했다.나는 당신의 질문을 거의 동일하게 물었다.그런 다음 몇 시간 후에 읽은 후에 나는 문제를 해결했습니다.내 답변 .
에 대한 링크가 있습니다.많은 유사한 질문에 대한 답변을 그렇게,그러나 어떻게든 그들 중 누구도 나를 위해 일하는 데 필요한 허용 만 초상화 형태에서 아이폰이, 고 만 풍경 모드에 iPad, 다,그래서 공유 나의 솔루션:
모두 제거 방법과 관련된 장치의 방향(
shouldAutoRotate, supportedInterfaceOrientations, preferredInterfaceOrientations
,etc.)으므로 수 충돌하는 서로 다른프로젝트에서 설정을 사용하는 모든 4 개의 형태:상,거꾸로,가로,왼쪽 풍경 권리
선택한 방법을 식별하기 위한 장치 유형(iPhone 또는 iPad).내가 사용하고
UIScreen.mainScreen().bounds.height which
이 이상적이지 않지만 나의 필요에 맞는다음에 AppDelegate
func application(application: UIApplication, supportedInterfaceOrientationsForWindow window: UIWindow?) -> UIInterfaceOrientationMask { if UIScreen.mainScreen().bounds.height < 760 { //iPhone UIApplication.sharedApplication().setStatusBarOrientation(.Portrait, animated: false); return UIInterfaceOrientationMask.Portrait; } else { UIApplication.sharedApplication().setStatusBarOrientation(.LandscapeLeft, animated: false); return UIInterfaceOrientationMask.Landscape; } }
에서 테스트 Xcode7.1.1 모든 아이폰과 아이 패드 시뮬레이터 실행 아이폰 os9.1