gpt4 book ai didi

iOS:如何交换横向 Xs 和 Ys

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:08:06 27 4
gpt4 key购买 nike

我的应用将只显示横向。我在宽度、高度、x 和 y 变量方面存在重大问题。有没有一种方法可以交换所有宽度、高度、x 和 y 值,这样我就不必反转应用程序中的所有坐标? (即 (x,y) 必须变成 (y,x) 并且 something.width 必须是 something.height。)

这是我的问题的一个具体例子:

-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [[event allTouches] anyObject];
CGPoint touchPoint = [touch locationInView:unitArea];

if (CGRectContainsPoint(self.view.frame, touchPoint))
{
NSLog(@"released in area");
}
}

这在景观中不起作用......它使用了错误的坐标,并且在某些地方,它会输出“在区域中发布”,但不是在 View 所在的实际区域中。

unitArea bounds are <UIView: 0x6a52420; frame = (20 0; 300 480); transform = [0, -1, 1, 0, 0, 0]; autoresize = RM+BM; layer = <CALayer: 0x6a524a0>>

这显示为我的 View 边界,而它应该是 (0 20; 480 300)。

编辑,更多信息:

这是我的(预制的)定向方法:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
} else {
return YES;
}
}

在项目摘要中,我的“支持的设备方向”仅设置为横向。

最佳答案

在 iOS 窗口中,坐标始终处于纵向模式。所以 rootViewController 的 View 框架将始终处于纵向模式。尝试在此 View 中插入另一个 View 。新 View 的框架必须更改方向以确认设备方向。

关于iOS:如何交换横向 Xs 和 Ys,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9794301/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com