ios - 滑动手势被误认为是触地

标签 ios swift uicontrolevents

我有一个 UIScrollView ,其中包含三个可以滑动到的部分。在每个部分上,都有一个 UIButton,用户应该选择其中一个按钮。我的问题是,如果用户滑动 UIButton,它会被意外选中。我的问题是,我应该将 UIButtons 设置为什么 UIControlEvent,这样他们就不会将滑动误认为是触摸?

这是我的按钮的代码:

    var button1 = UIButton(frame: CGRectMake((bigSizes.width * (50/960)), (bigSizes.height * 20/568), (bigSizes.width * 220/960), (bigSizes.height * 300/568)))
    button1.setImage(image1, forState: UIControlState.Normal)
    view1.addSubview(button1)
    button1.addTarget(self, action: "button1Pressed", forControlEvents: UIControlEvents.TouchUpInside)

最佳答案

如果您使用带有点击手势识别器的 UIImageView,则可以绕过此按钮问题:

var button1 = UIImageView(frame: CGRectMake((bigSizes.width * (50/960)), (bigSizes.height * 20/568), (bigSizes.width * 220/960), (bigSizes.height * 300/568)))
button1.image = image1
button1.userInteractionEnabled = true
view1.addSubview(button1)
let tap = UITapGestureRecognizer(target: self, action: "handleTap:")
button.addGestureRecognizer(tap)

显然是一个handleTap:方法:

func handleTap(gesture: UITapGestureRecognizer) {
    // handle tap
}

关于ios - 滑动手势被误认为是触地,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26409513/

相关文章:

ios - 在 TouchDown 离开控件之后、TouchUp 之前检测手指

ios - 映射包含错误的 SignalProducer 以返回 NoError

Arduino 的 iOS 远程控制

ios - 可拖动的 UIButton 不响应 UIControlEvents

ios - 我想在 iOS Swift 中摇动谷歌地图标记

ios - Swift3 Storekit - 将字符串数组转换为 Set<ProductIdentifier>

iphone - 为 UIControlStateNormal 添加目标不起作用

ios - 在同一列表/表格 View 中显示缓存的服务器联系人和本地 iOS 联系人

ios - map View 不关注注释

ios - 如何将当前位置坐标放入 google maps api(相机)