为什么detailViewController的框架总是返回1024*768

发布于 2024-12-10 20:33:38 字数 1037 浏览 0 评论 0原文

我有一个带有分割视图控制器的 iPad 应用程序。

我想以编程方式创建子视图并将其添加到右下角的detailViewController。为此,我尝试获取detailView的框架(应用程序支持自动旋转,因此位置不是静态的)

我接下来

在viewWillAppear中为detailView做我尝试获取框架并计算我需要的位置

- (void)viewWillAppear:(BOOL)animated {

  [super viewWillAppear:animated];    

    CGRect btnRect = self.view.frame;
    //it always return 1024*748 width and height
    //even in landscape mode
    //when as i think must return 1024-321=703*748 pxls
    //where is my mistake? How i can get actual frame
    //dimensions for detailViewController in landscape orientation

    btnRect.origin.y = btnRect.size.height - 42;
    btnRect.origin.x = btnRect.size.width - 42;
    btnRect.size.height = 42;
    btnRect.size.width = 42;

    UIButton* btn = [UIButton buttonWithType:UIButtonTypeCustom];
[btn setBackgroundImage:someimage forState:UIControlStateNormal];
[[btn layer] setFrame:btnRect];

   [self.view addSubview:btn];  
}

但它总是显示detailView框架有1024 * 748方面。当处于横向模式时,我认为它必须是 703*748。我需要做什么才能获得实际的详细视图框架?

I have an iPad app with split view controller.

I want to programmaticaly create and add subview to detailViewController in right bottom corner. To do that i try to get frame of detailView (app support autorotation, so that position not static)

i do next

in viewWillAppear for detailView i try to get frame and calculate position i need

- (void)viewWillAppear:(BOOL)animated {

  [super viewWillAppear:animated];    

    CGRect btnRect = self.view.frame;
    //it always return 1024*748 width and height
    //even in landscape mode
    //when as i think must return 1024-321=703*748 pxls
    //where is my mistake? How i can get actual frame
    //dimensions for detailViewController in landscape orientation

    btnRect.origin.y = btnRect.size.height - 42;
    btnRect.origin.x = btnRect.size.width - 42;
    btnRect.size.height = 42;
    btnRect.size.width = 42;

    UIButton* btn = [UIButton buttonWithType:UIButtonTypeCustom];
[btn setBackgroundImage:someimage forState:UIControlStateNormal];
[[btn layer] setFrame:btnRect];

   [self.view addSubview:btn];  
}

But it always show me that detailView frame has 1024*748 dimensions. When in landscape mode i think it must be 703*748. What i need to do to get actual detailView frame?

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

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

发布评论

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

评论(1

极度宠爱 2024-12-17 20:33:38

您应该希望在 shouldAutorotateToInterfaceOrientation 方法中更改视图的框架。

一个例子:
(这将调整scrollView2以适应其新方向(比主视图低88像素))

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations

    if (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {

        // Portrait
        self.scrollView2.frame = CGRectMake(0, 88, [UIScreen mainScreen].bounds.size.width, self.view.frame.size.height - 88);
        [self drawContent];
    }
    else {

        // Landscape
        self.scrollView2.frame = CGRectMake(0, 88, [UIScreen mainScreen].bounds.size.height, self.view.frame.size.width);
        [self drawContent];
    }


    return YES;
}

You should want to change the frame of the view in the shouldAutorotateToInterfaceOrientation method.

An example:
(This one will adjust scrollView2 to fit its new orientation (88 pixels lower then the mainview))

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations

    if (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {

        // Portrait
        self.scrollView2.frame = CGRectMake(0, 88, [UIScreen mainScreen].bounds.size.width, self.view.frame.size.height - 88);
        [self drawContent];
    }
    else {

        // Landscape
        self.scrollView2.frame = CGRectMake(0, 88, [UIScreen mainScreen].bounds.size.height, self.view.frame.size.width);
        [self drawContent];
    }


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