Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/117.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 请告诉我你对改变Avplayer方向的建议?_Ios_Iphone_Objective C - Fatal编程技术网

Ios 请告诉我你对改变Avplayer方向的建议?

Ios 请告诉我你对改变Avplayer方向的建议?,ios,iphone,objective-c,Ios,Iphone,Objective C,在我的应用程序中,所有视图都以Portait模式打开,但我想更改AVPlayer视图的模式,这意味着当用户进入此视图时,设备方向将自动更改为横向模式 我已经使用以下代码实现了这一点。它工作正常,我只想确认一下,通过使用以下代码,当我在appstore上传我的应用程序时,会有任何问题 -(void)viewDidAppear:(BOOL)animated { if(UIDeviceOrientationIsPortrait(self.interfaceOrientation)){

在我的应用程序中,所有视图都以
Portait
模式打开,但我想更改
AVPlayer视图的模式,这意味着当用户进入此视图时,设备方向将自动更改为
横向
模式

我已经使用以下代码实现了这一点。它工作正常,我只想确认一下,通过使用以下代码,当我在appstore上传我的应用程序时,会有任何问题

-(void)viewDidAppear:(BOOL)animated
{
    if(UIDeviceOrientationIsPortrait(self.interfaceOrientation)){
        if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)])
        {
            objc_msgSend([UIDevice currentDevice], @selector(setOrientation:), UIInterfaceOrientationLandscapeLeft );
        }
    }
}


-(void)viewDidDisappear:(BOOL)animated{

    if(UIDeviceOrientationIsLandscape(self.interfaceOrientation)){
        if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)])
        {
            objc_msgSend([UIDevice currentDevice], @selector(setOrientation:), UIInterfaceOrientationPortrait );
        }
    }
}
你可以找到关于类似问题的简短讨论。他们中没有一个人为我工作。这是我的工作

-(BOOL)shouldAutorotate
{
    return true;
}

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscape;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationLandscapeLeft |
           UIInterfaceOrientationLandscapeRight;
}

-(void) setSelfOrientation
{
    [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight];
    [self shouldAutorotate];

     self.view.transform = CGAffineTransformIdentity;
     self.view.transform = CGAffineTransformMakeRotation(M_PI_2);
    [self.view setFrame:CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.height, 
                     [[UIScreen mainScreen] bounds].size.width)];
}

-(void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];

    [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait]; // rollback previous orientation
    [self shouldAutorotate];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    [self setSelfOrientation];
}

是的,
setOrientation
是私有API。然后,请告诉我另一个旋转视图的选项,就像使用上述代码一样。如果需要,也可以使用UIView动画转换视图。通过使用代码,我的视图在横向模式下旋转,但我的导航栏不是旋转,状态栏也在Portait模式下,当我在横向模式下更改设备方向时,视图无法正确旋转。基本上,当iphone处于portait模式时,使用上述代码可以在横向模式下旋转视图。请帮助我您还需要设置导航控制器代码。请访问链接以及。