现在的位置: 首页 > 综合 > 正文

单页面旋转 ios

2017年10月06日 ⁄ 综合 ⁄ 共 1650字 ⁄ 字号 评论关闭

appdelega中添加的

@property (nonatomicassignBOOL allowRotation;


-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window


{


    if (self.allowRotation)
{


        return UIInterfaceOrientationMaskPortrait |UIInterfaceOrientationMaskLandscapeLeft |UIInterfaceOrientationMaskLandscapeRight;


    }


    return UIInterfaceOrientationMaskPortrait;


}



- (NSUInteger)supportedInterfaceOrientations


{


    return UIInterfaceOrientationMaskPortrait |UIInterfaceOrientationMaskLandscapeLeft |UIInterfaceOrientationMaskLandscapeRight;


}


- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation


{


    return UIInterfaceOrientationPortrait;



}

//要旋转的页面添加

1.添加通知


 NSNotificationCenter *NSDC = [NSNotificationCenter defaultCenter];





            [NSDC addObserver:self    selector:@selector(moviePlayerWillEnterFullscreenNotification:)


                         name:MPMoviePlayerWillEnterFullscreenNotification


                       object:_moviePlayer];


            [NSDC addObserver:self     selector:@selector(moviePlayerWillExitFullscreenNotification:)


                         name:MPMoviePlayerWillExitFullscreenNotification






























                       object:_moviePlayer];


2.实现方法


- (void)moviePlayerWillEnterFullscreenNotification:(NSNotification*)notify


{


    AppDelegate  *delegate = (AppDelegate *)[[UIApplication sharedApplicationdelegate];


    delegate.allowRotation = YES;


    NSLog(@"moviePlayerWillEnterFullscreenNotification");













}


- (void)moviePlayerWillExitFullscreenNotification:(NSNotification*)notify


{


    AppDelegate  *delegate = (AppDelegate *)[[UIApplication sharedApplicationdelegate];


    delegate.allowRotation = NO;


    [self.moviePlayer play];


    NSLog(@"moviePlayerWillExitFullscreenNotification");









}

抱歉!评论已关闭.