gpt4 book ai didi

iphone - 方向导航栏问题

转载 作者:行者123 更新时间:2023-11-29 13:37:27 25 4
gpt4 key购买 nike

我搜索了每个地方但没有找到解决方案我是 iphone 的新手。在每个地方我都设置了导航的高度或者我的 View 没有像问题那样在方向上旋转。我的 View 在旋转但是我的导航栏处于相同的位置,如果您有解决方案,请有人帮助我。谢谢,我已经在下面显示了一些代码,用于定位。当我点击我的标签栏时,我的模拟器会自动旋转,我希望标签栏也旋转但使用这个只有代码的模拟器是旋转的,不是标签栏和导航栏,对不起我的英语不好。

CGAffineTransform transform = CGAffineTransformIdentity;

switch ([[UIApplication sharedApplication] statusBarOrientation])
{

case UIInterfaceOrientationPortrait:
transform = CGAffineTransformMakeRotation(M_PI_2);
break;

default:
break;
}

[[UIApplication sharedApplication]setStatusBarOrientation:UIInterfaceOrientationPortrait];

[UIView animateWithDuration:0.2f animations:^ {

[self.navigationController.view setTransform:transform];

}];

[self.view setFrame:CGRectMake(0, 0, 320, 480)];
[self.view setNeedsLayout];

最佳答案

这段代码,无意冒犯,很好奇。我不确定您要做什么。你想解决什么问题?如果您不小心,使用 CGAffineTransform 肯定会产生奇怪的结果,就像您所描述的那样。

如果您只想确保您的应用成功支持横向和纵向,您可以在 View Controller 中实现 shouldAutorotateToInterfaceOrientation。执行此操作时,所有各种控件都会相应地重新定位。

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Support all orientations on iPad
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
return YES;

// otherwise, for iPhone, support portrait and landscape left and right

return ((interfaceOrientation == UIInterfaceOrientationPortrait) ||
(interfaceOrientation == UIInterfaceOrientationLandscapeLeft) ||
(interfaceOrientation == UIInterfaceOrientationLandscapeRight));
}

但是,如果我误解了您要尝试做的事情,即您正在尝试做一些比仅仅支持横向和纵向更复杂的事情,请告诉我。


我很抱歉,因为我不记得我最初是从哪里得到这段代码的(但它在 SO here 中被引用),但以下内容可用于强制横向:

首先,确保您的 shouldAutoRotateToInterfaceOrientation 应如下所示:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if ((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) ||
(interfaceOrientation == UIInterfaceOrientationLandscapeRight))
return YES;
else
return NO;
}

其次,在viewDidLoad中,添加如下代码:

if (UIDeviceOrientationIsPortrait([[UIDevice currentDevice] orientation]))
{
UIWindow *window = [[UIApplication sharedApplication] keyWindow];
UIView *view = [window.subviews objectAtIndex:0];
[view removeFromSuperview];
[window addSubview:view];
}

出于某种原因,从主窗口中删除 View 然后重新添加它会强制它查询 shouldAutorotateToInterfaceOrientation 并正确设置方向。鉴于这不是 Apple 批准的方法,也许应该避免使用它,但它对我有用。你的旅费可能会改变。但是that SO discussion也指其他技术。

关于iphone - 方向导航栏问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10191922/

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