天天看點

UIImageView 添加Button 不起作用

原文位址:http://hi.baidu.com/xf151362z/item/f370c9cef743331b0ad93a09

問題:

将一個UIButton 放在一個UIImageView上面,然後将這個UIImageView放在self.view上面,之前給UIButton添加的[button_buy addTarget:self action:@selector(buyButton) forControlEvents:UIControlEventTouchUpInside]響應事件,可怎麼就是不響應

原因:

UIView的userInteractionEnabled預設是YES

而UIImageView的userInteractionEnabled預設是NO

解決方法:

UIImageView有一個屬性userInteractionEnabled,把他設成yes就行了。否則UIImageView不能識别點選動作。