sách gpt4 ai đã đi

iphone - 边界] 横向时不改变

In lại 作者:行者123 更新时间:2023-12-03 21:20:52 27 4
mua khóa gpt4 Nike

我编写了一个应用程序,它有一个 UIViewController,它在纵向模式下显示另一个 UIViewController,在横向模式下显示不同的 UIViewController。

当我去风景时,我将绘制/放置东西,所以我需要获取风景坐标。下面是 iPhone 旋转时触发新 View 的代码。下面的代码是如何加载此 View 的。

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)x
duration:(NSTimeInterval)duration
{
if (UIInterfaceOrientationIsPortrait(x))
{
NSLog(@"Going Portrait");

} else if (UIInterfaceOrientationIsLandscape(x))
{
NSLog(@"Going Landscape");
if (activeView != [graphViewController view])
{
[containerView addSubview:[graphViewController view]];
}
}
}

我的问题是当

-(void)loadView {
CGRect screenBounds = [[UIScreen mainScreen] bounds];
NSLog(@"GraphViewController: Screenbounds %@", NSStringFromCGRect(screenBounds));
}

在 GraphViewController 返回中,它会生成:GraphViewController: Screenbounds {{0, 0}, {320, 480}}

这不是景观坐标,因此我的绘图不正确。如何使 GraphViewController 在调用 [UIScreen mainScreen]bounds]; 时具有正确的坐标?

非常感谢

迈克

1 Câu trả lời

我认为你的问题出在你建立的层次结构上。听起来像是当您添加第二个 View Controller 时,它认为它处于纵向模式(即使您处于横向模式)。我认为解决你的问题的方法是实现

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orientation

主视图 Controller 和图形 View Controller 中的方法。

但是,我认为这不是一条好路。您使用 uiviewcontrollers 而不仅仅是 uiviews 来显示不同的界面有什么具体原因吗?

如果你可以直接使用 UIViews,然后只需执行类似的操作

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)x
duration:(NSTimeInterval)duration
{
if (UIInterfaceOrientationIsPortrait(x))
{
NSLog(@"Going Portrait");

}
else if (UIInterfaceOrientationIsLandscape(x))
{
NSLog(@"Going Landscape");
if (activeView != graphView)
{
containerView = graphView;
//OR
[containerView addSubview:graphView];
}
}
}

我认为从长远来看你会过得更好,但你的选择。

关于iphone - 边界] 横向时不改变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4998314/

27 4 0
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com