旋转屏幕时如何调整 UIViewController 的框架大小?

发布于 2024-11-19 00:24:43 字数 1350 浏览 2 评论 0原文

我正在开发一个基于iPad 的程序。 我创建了新的模式 UIViewController 作为表单模式而不是全屏。 为了调整视图大小,我使用了以下代码。 ...

MyController* controller = [[MyController alloc] init];

controller.modalPresentationStyle = UIModalPresentationFormSheet;

[self presentModalViewController : controller animated: YES];

UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;

if ( UIInterfaceOrientationIsPortrait(orientation) )
    controller.view.superview.frame = CGRectMake(200, 100, 350, 600);
else
    controller.view.superview.frame = CGRectMake(100, 200, 600, 350);

...

在 MyController 中,我将以下代码编码为 didRotateFromInterfaceOrientation。

- (void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
    UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
    if ( fromInterfaceOrientation == orientation )
        return;
    if ( UIInterfaceOrientationIsPortrait(orientation) )
    {
        self.view.frame = CGRectMake(0, 0, 350, 600);
        self.view.superview.frame = CGRectMake(200, 100, 940, 628);
    }
    else
    {
        self.view.frame = CGRectMake(0, 0, 600, 350);
        self.view.superview.frame = CGRectMake(100, 200, 600, 350);
    }
}

但是当旋转屏幕时,视图不会调整大小,并且超级视图的宽度和高度具有意外的值。 请帮助我的问题。

I'm developing a program based iPad.
I created new modal UIViewController as formsheet mode not full screen.
And to resize the view, i used following codes.
...

MyController* controller = [[MyController alloc] init];

controller.modalPresentationStyle = UIModalPresentationFormSheet;

[self presentModalViewController : controller animated: YES];

UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;

if ( UIInterfaceOrientationIsPortrait(orientation) )
    controller.view.superview.frame = CGRectMake(200, 100, 350, 600);
else
    controller.view.superview.frame = CGRectMake(100, 200, 600, 350);

...

in MyController, i taked following codeds as didRotateFromInterfaceOrientation.

- (void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
    UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
    if ( fromInterfaceOrientation == orientation )
        return;
    if ( UIInterfaceOrientationIsPortrait(orientation) )
    {
        self.view.frame = CGRectMake(0, 0, 350, 600);
        self.view.superview.frame = CGRectMake(200, 100, 940, 628);
    }
    else
    {
        self.view.frame = CGRectMake(0, 0, 600, 350);
        self.view.superview.frame = CGRectMake(100, 200, 600, 350);
    }
}

but when rotate screen, the view don't be resized and width and height of superview has unexpect value.
please help my problem.

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

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

发布评论

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

评论(1

酒废 2024-11-26 00:24:43

尝试调试它,看看你实际上得到了什么方向。

你这样尝试过吗?

- (void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{

    if ( UIInterfaceOrientationIsPortrait(fromInterfaceOrientation) )
    {
        self.view.frame = CGRectMake(0, 0, 350, 600);
        self.view.superview.frame = CGRectMake(200, 100, 940, 628);
    }
    else
    {
        self.view.frame = CGRectMake(0, 0, 600, 350);
        self.view.superview.frame = CGRectMake(100, 200, 600, 350);
    }
}

另请注意,有两个肖像方向。

try to debug it and see what orientation you get in fact.

Did you try like this?

- (void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{

    if ( UIInterfaceOrientationIsPortrait(fromInterfaceOrientation) )
    {
        self.view.frame = CGRectMake(0, 0, 350, 600);
        self.view.superview.frame = CGRectMake(200, 100, 940, 628);
    }
    else
    {
        self.view.frame = CGRectMake(0, 0, 600, 350);
        self.view.superview.frame = CGRectMake(100, 200, 600, 350);
    }
}

Also note that there are two portairt orientations..

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