简体   繁体   中英

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. 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. If I move the settings UIButton to just outside that portion, it works as expected, even without switching view controllers. (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

在此输入图像描述

FirstViewController Attributes

在此输入图像描述

Containing view attributes that Settings UIButton is a child of

在此输入图像描述

Containing view metrics that Settings UIButton is a child of

在此输入图像描述

Settings UIButton Attributes

在此输入图像描述

Settings UIButton Metrics

在此输入图像描述

Settings UIButton Connections

在此输入图像描述

Z-Order of Elements in FirstViewController

在此输入图像描述

I've opened a new TabBar project and tested it, and everything works fine there. 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. 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:

[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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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