只有一个视图在xcode中自动旋转? [英] Only having one view autorotate in xcode?

查看:60
本文介绍了只有一个视图在xcode中自动旋转?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好,所以我目前有3个视图,我只需要一个视图即可自动旋转到任何方向,而其余视图则保持纵向.现在,我的设置是一个splashviewcontroller淡入视图A,而内部视图A是切换到视图B的按钮.我只希望视图B能够旋转到任何方向.

Ok so I currently have 3 views and I need only one of them to autorotate to any orientation while the rest stay in portrait. Right now my set up is a splashviewcontroller fades into view A, and inside view A is a button to switch to view B. All I want is for view B to be able to rotate to any orientation.

当我对初始视图控制器中的shouldautorotatetointerfaceorientation返回YES时,每个视图都会旋转,因为这是父视图.当我仅在启动视图中返回肖像时,即使其他视图返回是",也不会旋转.有没有办法只让视图B旋转?如果您可以提供代码,我愿意手动进行.谢谢

When I return YES for shouldautorotatetointerfaceorientation in the splashviewcontroller, every view rotates because this is the parent view. When I return portrait only in the splashview, nothing rotates even if the other views return YES. Is there a way to only have view B rotate? I'm willing to do it manually if you can provide code. Thanks

推荐答案

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

You can manually mange the rotation of any desired UIView object like so:

在init或viewDidLoad

In the init or 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, 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, 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 == UIInterfaceOrientationLandscapeRight){

        CGAffineTransform landscapeTransform = CGAffineTransformMakeRotation(degreesToRadian(90));

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


        [self.view setTransform:landscapeTransform];

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

        CGAffineTransform landscapeTransform = CGAffineTransformMakeRotation(degreesToRadian(270));

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

        [self.view setTransform:landscapeTransform];
    }

}

这篇关于只有一个视图在xcode中自动旋转?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆