ios转屏问题,某个界面需要支持转屏

我们在appdelegate 里面用代码把屏幕转向禁止

  • (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window { return UIInterfaceOrientationMaskPortrait; } 现在想要某一个界面支持转屏后横屏(UIInterfaceOrientationMaskPortrait不能改,其他界面要求竖屏)我需要怎么做 求大神指导

帮帮忙,不要沉。。啊

快来人哦,在线等呢。。。。。

//Appdelegate.h
@property(nonatomic,assign)BOOL Orientations;
//Appdelegate.m

  • (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window { if(Orientations) { return UIInterfaceOrientationMaskAllButUpsideDown; } return UIInterfaceOrientationMaskPortrait;

}

//要旋转的页面中
UIDevice *device = [UIDevice currentDevice]; //Get the device object
[device beginGeneratingDeviceOrientationNotifications]; //Tell it to start monitoring the accelerometer for orientation
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; //Get the notification centre for the app
[nc addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:device];

AppDelegate *delegate=[[UIApplication sharedApplication]delegate];
delegate.Orientations=YES;

  • (void)orientationChanged:(NSNotification *)note {
    UIDeviceOrientation o = [[UIDevice currentDevice] orientation];

    switch (o) {
    case UIDeviceOrientationPortrait: // Device oriented vertically, home button on the bottom

        break;
    case UIDeviceOrientationPortraitUpsideDown:  // Device oriented vertically, home button on the top
    
        break;
    case UIDeviceOrientationLandscapeLeft:      // Device oriented horizontally, home button on the right
        [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:YES];
    
        break;
    case UIDeviceOrientationLandscapeRight:      // Device oriented horizontally, home button on the left
        [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft animated:YES];
    
        break;
    default:
        break;
    

    }
    }

  • (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
    // 操作
    return YES; // YES为允许横屏,否则不允许横屏
    }

希望对你有帮助。

  • (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
    {
    if (self.allowRotation) {
    return UIInterfaceOrientationMaskAll;
    }

    return UIInterfaceOrientationMaskPortrait;

}
在appDelegate 定义一个bool的属性来控制特定页面是否可以旋转

给你一个建议 参照优酷播放器那种,使用仿射变换将界面转90度,然后自适应屏幕就行了,这是手动的,最好的方法