如何在导航控制器中自动旋转子视图

发布于 2024-10-03 23:14:25 字数 176 浏览 2 评论 0原文

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

我的问题是,如何使子视图自动旋转并具有像主视图的方向一样的方向???

有人可以帮助我吗...

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...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

葬花如无物 2024-10-10 23:14:25

我已经解决了这个问题。

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

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

然后,这是deviceRotated方法:

-(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);

    }   
}

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

I have solved this problem.

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]];

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文