如何在导航控制器中自动旋转子视图 [英] how to autorotate a subview in navigation controller

查看:128
本文介绍了如何在导航控制器中自动旋转子视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在导航控制器中有一个子视图,当ipad模拟器旋转为纵向或横向时,主视图自动适合ipad方向,但子视图不是。子视图也是旋转的,但不适合ipad方向,子视图方向始终朝向ipad主页按钮。

i have a subview in navigation controller, when the ipad simulator rotate to be portrait or landscape, the main view is autorotate fit into the ipad orientation, but the subview is not. the subview is rotate too, but not fit into the ipad orientation, the subview orientation is always landscape toward the ipad home button.

我的问题是,如何制作子视图自动旋转并具有主视图方向的方向???

my question is, how to make the subview autorotate and have orientation like the main view's orientation???

可以帮助我一些身体,请...

can some body help me, please...

推荐答案

我已经解决了这个问题。

I have solved this problem.

我在子视图viewController类中使用了NSNotification函数,在viewWillAppear方法中,这个是我的实现:

I use the NSNotification function in the subview viewController class, in the viewWillAppear method, this is my implementation:

[[NSNotificationCenter defaultCenter]
 addObserver:self
 selector:@selector(deviceRotated:)
 name:UIDeviceOrientationDidChangeNotification
 object:[UIDevice currentDevice]];

然后,这是deviceRotated方法:

and then, this is the deviceRotated method :

-(void)deviceRotated:(id)sender{
    UIDeviceOrientation orientation = [[UIDevice currentDevice]orientation];
    if (orientation == UIDeviceOrientationPortrait) {
        CGAffineTransform rotate = CGAffineTransformMakeRotation (0.0);
        CGAffineTransform translate = CGAffineTransformMakeTranslation(0, 30);
        self.alertView.transform = CGAffineTransformConcat(translate, rotate);

    }   
    else if (orientation == UIDeviceOrientationPortraitUpsideDown) {
        CGAffineTransform rotate = CGAffineTransformMakeRotation (M_PI * 180 / 180.0f);
        CGAffineTransform translate = CGAffineTransformMakeTranslation(-63, -100);
        self.alertView.transform = CGAffineTransformConcat(translate, rotate);

    }else if (orientation == UIDeviceOrientationLandscapeLeft) {
        CGAffineTransform rotate = CGAffineTransformMakeRotation (M_PI * 90 / 180.0f);
        CGAffineTransform translate = CGAffineTransformMakeTranslation(60, -180);
        self.alertView.transform = CGAffineTransformConcat(translate, rotate);


    }else if (orientation == UIDeviceOrientationLandscapeRight) {
        CGAffineTransform rotate = CGAffineTransformMakeRotation ( M_PI * 270 / 180.0f);
        CGAffineTransform translate = CGAffineTransformMakeTranslation(-60, -140);
        self.alertView.transform = CGAffineTransformConcat(translate, rotate);

    }   
}

最后,问题解决了。 这个是帮助我的链接。

Finally, the problem is solved. And this is the link that help me.

这篇关于如何在导航控制器中自动旋转子视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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