2013-11-28 37 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梅托德旋转使用

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

你的UIView您可以在特定视图 - 控制器实现didRotateFromInterfaceOrientation你不想受到影响。

0

了iOS 6后,你可以做这样的..

在AppDelegate.h文件

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

在AppDelegate.m文件

- (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; 
} 

并在您的视图 - 控制(这viewC你想改变方向)叫这个通知

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

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

根据您的代码,从应用程序开始,所有屏幕仅显示肖像模式。但我的要求是,除特定屏幕外,所有5个屏幕都应处于横向模式。当应用程序启动时,第一个屏幕应该处于横向模式,如果我进入第5个屏幕,它必须自动更改为纵向模式,这就是问题所在。 – Ramesh

相关问题