标签: uiinterfaceorientation

标签栏界面方向问题

我添加了一个自定义标签栏.包含更多选项卡的选项卡.

我的第一个标签仅支持纵向模式.第二个选项卡具有所有方向.

选择第二个选项卡并将其保持在横向模式,然后在横向模式下选择第一个选项卡时会出现问题.那时,第一个标签视图干净地旋转,但标签栏保持横向模式.

我怎样才能克服这种情况?这是自定义选项卡栏控制器中的应该旋转方法

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if (self.selectedIndex == 0) {

    return [self.selectedViewController shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationPortrait];

} else if (self.selectedIndex == 1) {

    return YES;
} 

return NO;}
Run Code Online (Sandbox Code Playgroud)

这是导航控制器的第一和第二视图控制器中应该旋转的方法

第一

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationPortrait);}
Run Code Online (Sandbox Code Playgroud)

第二

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;}
Run Code Online (Sandbox Code Playgroud)

iphone uitabbarcontroller uiinterfaceorientation

5
推荐指数
1
解决办法
1283
查看次数

iOS 6 UIInterfacePortrait ONLY视图控制器被呈现并卡在横向中...当从导航堆栈中的横向视图控制器返回时

就像许多其他人一样,我遇到的问题是只有一个或两个viewcontrollers支持纵向和横向界面方向,在另一个肖像应用程序中.在iOS 6之前一切正常,但突然自动停止工作.感谢这里的一些很好的问题,我能够通过让初始的navController通过以下方式返回个人topViewController对shouldAutorotate的首选项来解决这个问题:

    - (BOOL)shouldAutorotate
{
    return  self.topViewController.shouldAutorotate;
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAll;
}
Run Code Online (Sandbox Code Playgroud)

但是,我偶然发现了一个新问题.根vc(viewController A)不应该自动旋转,只应支持肖像.导航堆栈中的ViewController B支持纵向和横向.如果我在viewController B中,并且处于横向状态,并触摸"返回"以将视图弹回到viewController A ... vc A加载在横向中,它不应该支持,并且不会旋转回肖像,因为shouldAutorotate for vc A设置为NO ...

任何关于如何处理这个问题的想法将不胜感激.我最初的想法是使用手动方法覆盖vc B的"后退"按钮,如果视图处于横向状态,则首先强制旋转回纵向...然后将视图控制器弹回到vc A ......但我无法弄清楚如何以编程方式强制旋转.有任何想法吗?

这是vc A中的接口方法:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return NO;
}

-(BOOL)shouldAutorotate
{
    return NO;
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationPortrait;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    return UIInterfaceOrientationPortrait;
}
Run Code Online (Sandbox Code Playgroud)

这是他们在vc B中的内容:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return YES;
}

-(BOOL)shouldAutorotate
{
    return YES;
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAllButUpsideDown;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    return UIInterfaceOrientationPortrait;
}
Run Code Online (Sandbox Code Playgroud)

xcode objective-c uiinterfaceorientation autorotate ios6

5
推荐指数
1
解决办法
3851
查看次数

upSideDown iPhone方向在iOS 6中不起作用?

希望你会好起来,尽力而为.

upSideDown Orientation在我iOS 6身上遇到了问题,而我认为我做的一切都很完美,但我不知道为什么它不适合我.我和你分享我的问题,以便得到任何解决方案.

到目前为止我做了什么:

a)在xcode项目摘要选项卡中,我启用了所有4个方向.

b)我在所有控制器类中都添加了一段代码(如下所示).

-(BOOL)shouldAutorotate
{
    return YES;
}
-(NSInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAll;
}
Run Code Online (Sandbox Code Playgroud)

但仍然upSideDown Orientation无法正常工作

谢谢你的期待.

objective-c uiinterfaceorientation uideviceorientation ios6 xcode4.5

5
推荐指数
1
解决办法
3860
查看次数

我不知道如何在iOS 6中进行纵向和颠倒

我在用:

- (NSUInteger)supportedInterfaceOrientations {

    return UIInterfaceOrientationMaskPortrait; 

}
Run Code Online (Sandbox Code Playgroud)

如何在iOS6中将它用于纵向和颠倒?

这适用于景观左 UIInterfaceOrientationMaskLandscapeLeft

这对于风景吧 UIInterfaceOrientationMaskLandscapeRight

这适用于两种景观 UIInterfaceOrientationMaskLandscape

iphone xcode objective-c uiinterfaceorientation ios6

5
推荐指数
1
解决办法
1911
查看次数

除模态视图控制器外的所有视图控制器中的纵向方向

我正在使用代码呈现模态视图:

 [self presentViewController:movieViewController animated:YES completion:^{
     // completed
 }];
Run Code Online (Sandbox Code Playgroud)

在movieViewController中,控制器被解雇:

[self dismissViewControllerAnimated:YES completion:^{
    // back to previous view controller
}];
Run Code Online (Sandbox Code Playgroud)

目前,我的所有视图控制器都可以纵向和两个横向方向查看.

除了模态视图控制器之外,如何将所有视图控制器限制为纵向?因此,可以在三个方向中看到模态视图控制器,而在一个方向中可以看到其他所有内容.

objective-c uiviewcontroller uiinterfaceorientation ios

5
推荐指数
1
解决办法
4000
查看次数

Segue导致UITabBarController在Swift中移动状态栏?

关于我如何限制屏幕方向,我遇到了一个奇怪的问题.

这是我的故事板的样子:

在此输入图像描述

我的屏幕方向设置为仅限肖像.

在我的AppDelegate中,我有以下内容:

func application(application: UIApplication, supportedInterfaceOrientationsForWindow window: UIWindow?) -> UIInterfaceOrientationMask
{
    if self.window?.rootViewController?.presentedViewController is VideoPlayerViewController
    {
        return UIInterfaceOrientationMask.Landscape;
    }
    else
    {
        return UIInterfaceOrientationMask.Portrait;
    }
}
Run Code Online (Sandbox Code Playgroud)

在"主页"选项卡中,单击"红色"播放按钮或任何单元格将对我执行一个segue VideoPlayerViewController.我只限制了VideoPlayerViewController景观.

但是,就在segue发生之前,会发生这种情况:

在此输入图像描述在此输入图像描述

基本上,正在发生的事情是,在第二张图片中,红色部分向上移动,将状态栏推开.

然后在第3张照片中,前2个标签稍微向左移动,而最后2个标签稍微向右移动.

再次,所有这一切都发生在模态segue发生之前.

可能是什么导致了这个?如果我需要包含其他代码,请告诉我..

uitabbarcontroller uiinterfaceorientation ios swift

5
推荐指数
1
解决办法
208
查看次数

iOS ARKit 应用程序:如何旋转 UI(屏幕)而不旋转内部相机视图?

我正在尝试使用 ARKit 制作一个具有一些 AR 体验的 iOS 应用程序。该应用程序现在有一个启动视图,其中有一个“开始”按钮(在应用程序刚刚启动后首先显示)和一个 AR 视图(在我点击启动视图中的“开始”按钮后显示),并且我还为每个控制器提供了视图控制器。AR 视图本质上是一个全屏 ARSCNView,它显示来自相机的实时图像,以及一些 UIButtons。

所有的事情似乎都运作良好,直到我想指定每个阶段的方向。需要将启动视图设置为纵向,将 AR 视图设置为横向。为了自动更改屏幕方向,我尝试将以下代码添加到viewDidLoad()AR ViewController 中:

let value = UIInterfaceOrientation.landscapeRight.rawValue
UIDevice.current.setValue(value, forKey: "orientation")
Run Code Online (Sandbox Code Playgroud)

并设置

override var shouldAutorotate: Bool {
    return false
}
Run Code Online (Sandbox Code Playgroud)

然而,它的效果并不好 --- 尽管 UI 的方向已正确更改,但相机预览也“旋转”了 90 度(因此您从应用程序中看到的所有图像都将旋转 90 度):

image1 (设备现在是物理纵向的,相机视图在某种程度上是垂直的)

image2 (设备现在物理上处于横向右侧,但相机视图仍然是垂直的)

我还尝试了另一种方法:

override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
    return UIInterfaceOrientationMask.landscapeRight
}
Run Code Online (Sandbox Code Playgroud)

但结果还是一样。

我希望它如下所示,UI 固定在横向右侧,但相机始终处于正常方向(重力向下):

image3 (这是在允许自动旋转的情况下捕获的,但我希望它在切换到此视图时自动旋转!)

任何帮助或提示将不胜感激!

uiinterfaceorientation ios arkit arscnview

5
推荐指数
0
解决办法
736
查看次数

iOS 16 中报告错误的界面方向

我一直在使用以下方法来检测 iOS 14/15 中当前的界面方向:

UIApplication.shared.windows.first!.windowScene!.interfaceOrientation 
Run Code Online (Sandbox Code Playgroud)

现在,在 iOS 16 Beta(1 和 2)中,它的报告不正确。风景被报道为肖像颠倒。

xcode rotation uiinterfaceorientation ios swift

5
推荐指数
1
解决办法
5844
查看次数

UIOrientation返回0或5

我正在运行一个简单的函数,可以在多个区域调用,以帮助在方向更改期间处理iPad应用程序上的布局.它看起来像这样:

- (void) getWidthAndHeightForOrientation:(UIInterfaceOrientation)orientation {
    NSLog(@"New Orientation: %d",orientation);
end
Run Code Online (Sandbox Code Playgroud)

我在各种各样的地方称它为:

[self getWidthAndHeightForOrientation: [[UIDevice currentDevice] orientation]];
Run Code Online (Sandbox Code Playgroud)

该函数通常有一些简单的代码,如果方向是纵向或横向,则运行.不幸的是,当应用程序以位置1开始时,它没有按预期工作.结果我得到0.稍后如果以相同的方式调用该函数但该设备从未被旋转,则返回值5.这是什么意思?为什么会抛出这些值?

简而言之,为什么[[UIDevice currentDevice] orientation]会抛出0或5而不是1到4之间的任何值?

更新:

因为处理方向的方式我在代码中不断发现错误,所以我写了一篇关于如何处理UIDevice或UIInterface方向的权威帖子:http://www.donttrustthisguy.com/orientating-yourself-in-ios

iphone objective-c orientation ipad uiinterfaceorientation

4
推荐指数
1
解决办法
3323
查看次数

方向更改时的UIScrollview内容大小

我有一个分页的滚动视图.在viewDidLoad中,我检查当前方向是否为横向,然后我设置其内容大小的高度440

 if (UIDeviceOrientationIsPortrait([[UIDevice currentDevice] orientation])) 
    {
        [scroll      setContentSize:CGSizeMake(self.scroll.frame.size.width*numberOfPages,340)];


    }
    else if (UIDeviceOrientationIsLandscape([[UIDevice currentDevice] orientation]))

    {
        [scroll setFrame:CGRectMake(0,0,480,480)];
        [scroll setContentSize:CGSizeMake(self.scroll.frame.size.width*numberOfPages, 440)];


    }
Run Code Online (Sandbox Code Playgroud)

一切正常滚动视图滚动顺畅,没有对角线滚动.

但是当方向改变时

我必须再次设置scrollview的框架和内容,我将其设置如下

-(void)orientationChanged:(id)object
{
if(UIDeviceOrientationIsPortrait([[UIDevice currentDevice] orientation]))
{
    self.scroll.frame = [[UIScreen mainScreen]bounds];

    [scroll setContentSize:CGSizeMake(self.scroll.frame.size.width*numberOfPages, 340)];
}


else
{
 self.scroll.frame = CGRectMake(0,0,480,480);
        [scroll setContentSize:CGSizeMake(self.scroll.frame.size.width*numberOfPages, 600)];
}


}
Run Code Online (Sandbox Code Playgroud)

我不明白为什么我必须在横向模式下将内容大小的高度设置为600,这太不够了.并且它增加了另一个问题,即scrollview开始对角线滚动,我不想要,因为它看起来很奇怪.任何人都可以帮我理解我错过的地方和地点吗?

我已将scrollview的自动调整遮罩设置为

[scroll setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin|UIViewAutoresizingFlexibleHeight];
Run Code Online (Sandbox Code Playgroud)

但改变它没有帮助.

objective-c uiscrollview uiinterfaceorientation ios contentsize

4
推荐指数
1
解决办法
1万
查看次数