iphone - UIScrollView 中的 iOS 5 UIButtons 不可点击

标签 iphone ios objective-c uiscrollview uibutton

我有一个奇怪的错误,即 UIView 内的两个 UIButtons,而 UIScrollView View 内的两个 UIButton 在 iOS 5 上不可点击,但在 iOS 6 上工作得非常好(屏幕截图显示滚动条和下面的 map )

唯一的其他细节是 ScrollView “向上滑动”以在选择电台时显示按钮。我试过在 iOS 5 上选择按钮,它们确实被击中(视觉上),但没有触发事件。

编辑 :如果我点击并按住模拟器中的按钮,然后将光标向上移动到屏幕上并释放(例如,到始终可见的 UIView 部分),事件就会触发。

Scroller Sample

ScrollView 本身有以下设置,后两个只是为了尝试使按钮在 iOS 5 上工作而添加的(尝试了各种组合):

self.scrollView.clipsToBounds = YES;
self.scrollView.scrollEnabled = YES;
self.scrollView.pagingEnabled = YES;
self.scrollView.delaysContentTouches = NO;
self.scrollView.canCancelContentTouches = NO;

按钮事件都正确连接,具有合适的目标等:
[_updatePriceButton addTarget:self action:@selector(showPriceUpdateBoxWithPrice:) forControlEvents:UIControlEventTouchUpInside];
[_stationDetailsButton addTarget:self action:@selector(stationDetailsSelected:) forControlEvents:UIControlEventTouchUpInside];

和处理程序(这里有一个作为示例):
- (void)stationDetailsSelected:(id)sender {
    if ([self.delegate respondsToSelector:@selector(stationDetailsSelected:)]) {
        [self.delegate stationDetailsSelected:_station];
    }
}

任何帮助都会很棒!

最佳答案

找到了罪魁祸首——在 UIButton 所在的 UIView 上配置错误的 UITapGestureRecognizer:

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(stationInfoViewTapped:)];
[infoController.view addGestureRecognizer:tap];

只需在“tap”的 init 之后添加以下内容即可解决 iOS 5 中的问题:
[tap setCancelsTouchesInView:NO];

关于iphone - UIScrollView 中的 iOS 5 UIButtons 不可点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15624039/

相关文章:

ios - 我可以将应用程序设置为在 iOS 上的设备空闲时运行吗?

iphone - 保存登录凭据 Xcode

ios - 无法加载4S拍摄的图像,但可以加载5S

ios - 通过数组循环下载图像时的内存问题

javascript - InAppBrowser 在 iOs 10 上打开空白页面

ios - 通过heroku解析服务器在单个设备上发送推送通知

ios - 继续 : what happens to the controller instance that calls the seque?

iphone - 电子邮件在 ShareKit 中不起作用且没有错误

objective-c - UILabel 文本被截断

Objective-C : Object declaration question