-->

My button doesn't detect touch events on iPhon

2019-01-18 02:51发布

问题:

I'm getting my app ready for the iPhone 5 using the simulator and I've found a weird issue where a couple of my buttons, in one of my views, don't work in the iPhone (Retina 4-inch) simulator, but work fine in the iPhone (Retina 3.5-inch) simulator. The buttons simply don't do anything when they're tapped. Has anyone else experienced this issue?

I having a difficult time figuring out where to start with this one. Any suggestions on where to start?

Thanks so much in advance for all your wisdom!

回答1:

You need to edit your MainWindow.xib and enable "Full Screen at Launch". For a more detailed explanation, see Apple's docs:

Important: When creating your window in Interface Builder, it is recommended that you enable the Full Screen at Launch option in the attributes inspector. If this option is not enabled and your window is smaller than the screen of the target device, touch events will not be received by some of your views. This is because windows (like all views) do not receive touch events outside of their bounds rectangle. Because views are not clipped to the window’s bounds by default, the views still appear visible but events do not reach them. Enabling the Full Screen at Launch option ensures that the window is sized appropriately for the current screen.

Complete document from Apple



回答2:

For me, the solution was to set the size ("Simulated Metrics") to "Retina 4 Full Screen" for the MainWindow.xib. I did not need to alter the size of the other screens (they are still set to None). After changing the MainWindow.xib the bottom area becomes clickable again...



回答3:

The problem was caused by another control overlapping my buttons due to the way the springs and struts were setup. Adjusting the z-order of the buttons fixed the issue. Thanks, all!



回答4:

There are two solution to this problem :

If you are using MainWindow follow these steps :

a. Select MainWindow.xib.

b. Select Full Screen at Launch from Windows option available in Attributes Inspector.

If your application doesn't contain MainWindow then just add:

self.view.frame = [UIScreen mainScreen].bounds

in ViewDidLoad.



回答5:

I solved my prob.

view .origin for 3.5 inch and 4 inch screen are different so, when writing common code for both we need to take care at giving CGRectmake(x,y,w,h);

Set temp. diff background color of diff view so you can check if any view is overlapping or not, to fetch event in 4.0 inch.