简体   繁体   English

iOS AutoLayout故事板横向方向UIButton不接受触摸

[英]iOS AutoLayout Storyboard Landscape Orientation UIButton doesn't accept touch

I have a Tab Bar Application, the first view controller has a settings UIButton in the top right hand corner. 我有一个标签栏应用程序,第一个视图控制器右上角有一个设置UIButton。 When you rotate to landscape mode, it doesn't accept touch events. 旋转到横向模式时,它不接受触摸事件。 Rotate to portrait it does. 旋转到肖像它。 Switch view controllers, and switch back. 切换视图控制器,然后切换回来。 Everything works fine in both orientations. 一切都在两个方向都很好。

Interestingly, the UITableView that's also on the right hand side in landscape mode, seems to only accept touch events on a certain portion of it. 有趣的是,在横向模式下也位于右侧的UITableView似乎只接受其某一部分的触摸事件。 If I move the settings UIButton to just outside that portion, it works as expected, even without switching view controllers. 如果我将设置UIButton移动到该部分之外,即使没有切换视图控制器,它也能按预期工作。 (I know what you're thinking, something is above it. As far as I can tell nothing is, I have changed all the views and subviews to have a different background, and nothing is out of place or not as expected. (我知道你在想什么,有些东西在它之上。据我所知,我已经改变了所有的观点和子视图以具有不同的背景,没有任何不合适的地方或没有预期的。

I'm including the settings for all the relevant components... 我包括所有相关组件的设置......

TabBarViewController Attributes TabBarViewController属性

在此输入图像描述

FirstViewController Attributes FirstViewController属性

在此输入图像描述

Containing view attributes that Settings UIButton is a child of 包含Settings UIButton是其子级的视图属性

在此输入图像描述

Containing view metrics that Settings UIButton is a child of 包含设置UIButton是其子级的视图度量标准

在此输入图像描述

Settings UIButton Attributes 设置UIButton属性

在此输入图像描述

Settings UIButton Metrics 设置UIButton指标

在此输入图像描述

Settings UIButton Connections 设置UIButton连接

在此输入图像描述

Z-Order of Elements in FirstViewController FirstViewController中的Z-Order元素

在此输入图像描述

I've opened a new TabBar project and tested it, and everything works fine there. 我已经打开了一个新的TabBar项目并对其进行了测试,一切正常。 It seems like something is over the right side, but nothing appears to be. 似乎有些东西在右侧,但似乎没有任何东西。

Problem is 'frame not set' of your view or view controller. 问题是视图或视图控制器的“未设置框架”。 You need to check, your view/viewcontroller's frame is not getting change when you change the orientation. 您需要检查,更改方向时,您的view / viewcontroller的框架没有变化。 SubViews will show as per their positon , but I am pretty sure that their parentview's frame is not according to landscape mode that is why your table is also not responding. 子视图将根据他们的位置显示,但我很确定他们的父视图的框架不符合横向模式,这就是您的表也没有响应的原因。 Try to set its bound as view's frame when orientation changes. 当方向改变时,尝试将其边界设置为视图的框架。

Add the following line to the viewDidLoad method of your controller: 将以下行添加到控制器的viewDidLoad方法:

[self.view setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight];

Another thing, to look for overlapping views, use the color blended layers option in the debug menu of the simulator. 另外,要查找重叠视图,请使用模拟器调试菜单中的颜色混合图层选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM