为什么detailViewController的框架总是返回1024*768
我有一个带有分割视图控制器的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该希望在 shouldAutorotateToInterfaceOrientation 方法中更改视图的框架。
一个例子:
(这将调整scrollView2以适应其新方向(比主视图低88像素))
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))