iOS   发布时间:2022-05-03  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了iphone – 只有一个视图在xcode中自动旋转?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

好的,所以我目前有3个视图,我只需要其中一个自动旋转到任何方向,而其余的保持纵向.现在我的设置是一个splashviewcontroller淡入视图A,内部视图A是一个切换到视图B的按钮.我想要的是视图B能够旋转到任何方向. 当我在splashviewcontroller中为shouldautorotatetointerfaceorientation返回YES时,每个视图都会旋转,因为这是父视图.
好的,所以我目前有3个视图,我只需要其中一个自动旋转到任何方向,而其余的保持纵向.现在我的设置是一个splashviewcontroller淡入视图A,内部视图A是一个切换到视图B的按钮.我想要的是视图B能够旋转到任何方向.

当我在splashviewcontroller中为shouldautorotatetointerfaceorientation返回YES时,每个视图都会旋转,因为这是父视图.当我仅在splashview中返回肖像时,即使其他视图返回YES,也不会旋转.有没有办法让视图B旋转?如果你能提供代码,我愿意手动完成.谢谢

解决方法

你可以手动管理任何所需的UIView对象的旋转,如下所示:

编辑:

在init或viewDidLoad中

- (void)viewDidLoad
{
    [[NsnotificationCenter defaultCenter] addObserver:self SELEctor:@SELEctor(rotatE) name:UIDeviceOrientationDidChangeNotification object:nil];

    [super viewDidLoad];
}

#define degreesToRadian(X) (M_PI * (X) / 180.0)

-(void)rotate{

    self.view.bounds = CGRectMake(0,0);

    if ([UIDevice currentDevice].orientation == UIInterfaceOrientationPorTrait){


        CGAffineTransform landscapeTransform = CGAffineTransformMakeRotation(degreesToRadian(0));
        landscapeTransform = CGAffineTransformTranslate (landscapeTransform,0.0,0.0);

        self.view.bounds = CGRectMake(self.view.bounds.origin.x,self.view.bounds.origin.y,320,480);

        [self.view setTransform:landscapeTransform];


    } else if ([UIDevice currentDevice].orientation == UIInterfaceOrientationPorTraitUpsideDown){


        CGAffineTransform landscapeTransform = CGAffineTransformMakeRotation(degreesToRadian(180));
        landscapeTransform = CGAffineTransformTranslate (landscapeTransform,480);

        [self.view setTransform:landscapeTransform];

    } else if ([UIDevice currentDevice].orientation == UIInterfaceOrientationLandscapeRight){

        CGAffineTransform landscapeTransform = CGAffineTransformMakeRotation(degreesToRadian(90));

         landscapeTransform = CGAffineTransformTranslate (landscapeTransform,0.0);
         self.view.bounds = CGRectMake(self.view.bounds.origin.x,480,320); 


        [self.view setTransform:landscapeTransform];

    }else if ([UIDevice currentDevice].orientation == UIInterfaceOrientationLandscapeLeft){

        CGAffineTransform landscapeTransform = CGAffineTransformMakeRotation(degreesToRadian(270));

        landscapeTransform = CGAffineTransformTranslate (landscapeTransform,0.0);
        self.view.bounds = CGRectMake(self.view.bounds.origin.x,320); 

        [self.view setTransform:landscapeTransform];
    }

}

大佬总结

以上是大佬教程为你收集整理的iphone – 只有一个视图在xcode中自动旋转?全部内容,希望文章能够帮你解决iphone – 只有一个视图在xcode中自动旋转?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。