My button doesn't detect touch events on iPhon

2019-01-18 02:36发布

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!

5条回答
劫难
2楼-- · 2019-01-18 03:15

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!

查看更多
Luminary・发光体
3楼-- · 2019-01-18 03:22

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.

查看更多
乱世女痞
4楼-- · 2019-01-18 03:29

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.

查看更多
Summer. ? 凉城
5楼-- · 2019-01-18 03:30

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

查看更多
We Are One
6楼-- · 2019-01-18 03:35

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

查看更多
登录 后发表回答