wkwebview进入全屏,退出全屏

2018-07-16  本文已影响30人  代码

1.在view did load方法里写:

//将要进入全屏

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(startFullScreenNew) name:UIWindowDidResignKeyNotification object:nil];

    //退出全屏

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(endFullScreenNew) name:UIWindowDidBecomeHiddenNotification object:nil];

-(void)startFullScreenNew {

    NSLog(@"进入全屏");

    UIApplication *application=[UIApplication sharedApplication];

    [application setStatusBarOrientation: UIInterfaceOrientationLandscapeRight];

    application.keyWindow.transform=CGAffineTransformMakeRotation(M_PI/2);

    CGRect frame = [UIScreen mainScreen].applicationFrame;

    application.keyWindow.bounds = CGRectMake(0, 0, frame.size.height + 20, frame.size.width);

}

-(void)endFullScreenNew {

    NSLog(@"退出全屏XXXX");

    UIApplication *application=[UIApplication sharedApplication];

    [application setStatusBarOrientation: UIInterfaceOrientationLandscapeRight];

    CGRect frame = [UIScreen mainScreen].applicationFrame;

    application.keyWindow.bounds = CGRectMake(0, 0, frame.size.width, frame.size.height);

    //application.keyWindow.bounds = CGRectMake(0, 0, frame.size.width, frame.size.height + 20)

    [UIView animateWithDuration:0.25 animations:^{

        application.keyWindow.transform=CGAffineTransformMakeRotation(M_PI * 2);

    }];

}

appDelegate中:

- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {

    if ([NSStringFromClass([[[window subviews]lastObject] class]) isEqualToString:@"UITransitionView"]) {

        return UIInterfaceOrientationMaskAll;

    }

//    if (self.allowRotation) {

//        return UIInterfaceOrientationMaskAll;

//    }

    return UIInterfaceOrientationMaskPortrait;

}

上一篇 下一篇

猜你喜欢

热点阅读