2014-10-16 36 views
2

我有一個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) 

回答

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 
}