简体   繁体   中英

UIButton Not Getting Event When Tapped

My iOS 7 app has a UIViewController with a UIMapView on it. It also has a small view with a UIButton on it that is displayed over the map when the user drags the map outside the current search area. When it is displayed, the user can tap the button to search for more POIs around the current map center.

I am using Apple's BannerViewController from the iAd Suite sample code so I can display one ad banner across multiple views. This required me to embed the view controller in a container so that the BannerViewController could show/hide the ad. Now, when the small view with the button on it is displayed, touching the button does not trigger the Touch Up Inside event like it did before.

I am using Interface Builder and have checked all of the views in the view hierarchy and they all have User Interaction Enabled. Here is what the view hierarchy looks like in IB:

BannerViewController的MapViewController

I know this is probably something dumb I am not thinking of, but I have been looking at it too long and need some help.

Thanks in advance.

UPDATE #1 :

I removed the UIButton from the small view and replaced it with a tap gesture recognizer and still nothing. It appears that the view itself is not getting any touch events.

UPDATE #2 :

Bringing the button to to the front using bringSubviewToFront does not help.

Update #3 :

Here's a list of the subviews of the container view controller:

<__NSArrayM 0x17c74ea0>(
<MKMapView: 0x15ddfe40; frame = (0 0; 320 367); clipsToBounds = YES; autoresize = TM+BM; layer = <CALayer: 0x15de1e90>>,
<UIView: 0x17c00030; frame = (0 317; 320 50); alpha = 0; autoresize = TM+BM; layer = <CALayer: 0x15d42dc0>>,
<_UILayoutGuide: 0x17c000f0; frame = (0 0; 0 0); hidden = YES; layer = <CALayer: 0x17c75400>>,
<_UILayoutGuide: 0x17c00160; frame = (0 0; 0 0); hidden = YES; layer = <CALayer: 0x17c751d0>>
)

I was right, it was stupid. After all of everyone's comments, I checked the container and I had set no auto layout constraints on it. From my experience, this means that it will be created with all zeros for it's frame. Once I added those constraints, everything started working fine again.

Thanks to all who helped me track this down.

如果您正在尝试使用iOS模拟器。请退出iOS模拟器并再次运行您的应用程序,如果您的代码中的所有内容都在那里。

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