我有一个UIScrollView
,其中有三个部分可以刷到。在每个部分,有一个UIButton
,用户应该选择一个按钮。我的问题是,如果用户滑过UIButton
,则会意外选择它。我的问题是,UIControlEvent
我应该将UIButtons
设置为 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)
,以便他们不会误认为轻触一下?
这是我按钮的代码:
{{1}}
答案 0 :(得分:2)
如果您使用带有点击手势识别器的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
}