2013-11-28 3 views
-1

나는 IOS에 더 신선하다. 내 iPad 응용 프로그램에서 나는 6보기가 있습니다. 기본적으로 모든 화면에 대해 방향을 가로 모드로 고정했습니다. 그러나 제 5 번째보기는 세로보기 모드와 같이 변경해야합니다. 특정보기 방향을 변경하는 프로그램 코드가 있습니까? 이 문제를 도와 주시겠습니까? 미리 감사드립니다.ipad에서 모든보기가 아닌 단일보기의 방향을 변경하는 방법은 무엇입니까?

+0

어떤 iOS 버전을 사용하고 있습니까? – Dilip

답변

0

1.You는 의

-(void)beginGeneratingDeviceOrientationNotifications 

메소드를 호출 DeviceOrientation 통지를 생성 할 필요가있다. 보기 알림 관찰을 추가 제어

2.in의 UIViewController는

[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(rotateMyUIView:) name:UIDeviceOrientationDidChangeNotification object:nil]; 

3.in rotateMyUIView는 metod 당신은 특정 뷰 - 컨트롤러에 didRotateFromInterfaceOrientation을 구현할 수

myView.transform = CGAffineTransformMakeRotation(M_PI/2); // you must check orientation first 
0

를 사용하여 UIView의 회전하는 당신을 영향을 받기를 원하지 않았다. 아이폰 OS 6 후

0

당신은 이런 식으로 작업을 수행 할 수 있습니다 .. AppDelegate.h에서

이 AppDelegate.m에서

@interface AppDelegate : UIResponder <UIApplicationDelegate> 
{ 
    BOOL allowRotation; 
} 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    allowRotation = NO; 
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeDeviceOrientation:) name:@"ChangeDeviceOrientation" object:nil]; 

    return YES; 
} 

- (void) changeDeviceOrientation:(NSNotification*)notification { 
    if(allowRotation) 
    { 
     allowRotation = NO; 
    }else 
    { 
     allowRotation = YES; 
    } 
} 

-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window 
{ 
    NSLog(@"Not FullScreen"); 
    if (allowRotation) { 
     NSLog(@"FullScreen"); 
     return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight; 
    } 
    return UIInterfaceOrientationMaskPortrait; 
} 

그리고 당신의 ViewController에 파일을 파일 (어느 viewC 방향 변경)

-(void)viewWillDisappear:(BOOL)animated{ 
    [[NSNotificationCenter defaultCenter] postNotificationName:@"ChangeDeviceOrientation" object:nil]; 
} 

-(void)viewWillAppear:(BOOL)animated 
{ 
    [[NSNotificationCenter defaultCenter] postNotificationName:@"ChangeDeviceOrientation" object:nil]; 
} 
+0

코드에 따라, 응용 프로그램에서 앞으로 표시되는 모든 화면에 세로 모드 만 표시됩니다. 하지만 내 요구 사항은, 모든 5 화면은 특정 화면을 제외하고 가로 모드에 있어야합니다. 응용 프로그램이 시작될 때 첫 번째 화면이 가로 모드 여야합니다. 다섯 번째 화면에 들어가면 자동으로 세로 모드로 변경해야합니다. – Ramesh