Хорошо, я получил эту работу, вот что вы должны сделать:
@IBOutlet weak var profileImage: UIImageView!
let recognizer = UITapGestureRecognizer()
Создайте метод, чтобы сказать вам, когда изображение было похлопал
func profileImageHasBeenTapped(){
println("image tapped")
}
Большой , теперь в вашем методе viewDidLoad
напишите три другие строки кода, чтобы получить эту работу
override func viewDidLoad() {
super.viewDidLoad()
//sets the user interaction to true, so we can actually track when the image has been tapped
profileImage.userInteractionEnabled = true
//this is where we add the target, since our method to track the taps is in this class
//we can just type "self", and then put our method name in quotes for the action parameter
recognizer.addTarget(self, action: "profileImageHasBeenTapped")
//finally, this is where we add the gesture recognizer, so it actually functions correctly
profileImage.addGestureRecognizer(recognizer)
}
Убедитесь, что 'userInteractionEnabled' установлен в' true'. Я считаю, что это 'false' по умолчанию для' UIImageView'. – AdamPro13
@ AdamPro13 все еще не работает с кодом, который у меня выше. –