iOS控制屏幕旋转

来源:互联网 发布:域名权重批量查询工具 编辑:程序博客网 时间:2024/05/15 05:52

- (BOOL) shouldAutorotate

{

    return YES;

}

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration

{

    NSLog(@"kkkk");

}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event

{

    NSLog(@"touch");

    if (_b==NO) {

        //这句话是防止手动先把设备置为横屏,导致下面的语句失效.

        [[UIDevicecurrentDevice] setValue:[NSNumbernumberWithInteger:UIDeviceOrientationPortrait]forKey:@"orientation"];

        

        [[UIDevicecurrentDevice] setValue:[NSNumbernumberWithInteger:UIDeviceOrientationLandscapeLeft]forKey:@"orientation"];


    }

    else

    {

        //横屏点击按钮,旋转到竖屏

        [[UIDevicecurrentDevice] setValue:[NSNumbernumberWithInteger:UIDeviceOrientationLandscapeLeft]forKey:@"orientation"];//这句话是防止手动先把设备置为竖屏,导致下面的语句失效.

        [[UIDevicecurrentDevice] setValue:[NSNumbernumberWithInteger:UIDeviceOrientationPortrait]forKey:@"orientation"];


    }

    //    [self shouldAutorotate];

}

0 0
原创粉丝点击