I had the following code:
UITapGestureRecognizer *showStoryTapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showNewsStory
UIImageView
has user interaction disabled by default, unlike most other UIView
subclasses in UIKit.
use lazy var instead of let . Here is an example.
lazy var loginSignUpView: LoginSignUpView = {
let lsv = LoginSignUpView()
lsv.loginRegisterButton.addTarget(self, action: #selector(handleLoginRegistrationButton), for: .touchUpInside)
lsv.segmentedControlForLoginRegister.addTarget(self, action: #selector(handleSegmentedControlForLoginRegister), for: .valueChanged)
lsv.profileImageView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(handleSelectProfileImageView)))
return lsv
}()
@objc func handleSelectProfileImageView() {
print("Image tapped")
}
objective-c ios 10
UITapGestureRecognizer *oneTouch=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(OneTouchHandeler)];
[oneTouch setNumberOfTouchesRequired:1];
[imageView addGestureRecognizer:oneTouch];
imageView.userInteractionEnabled = YES;
// swift 3.0
let oneTouch = UITapGestureRecognizer(target: self, action: #selector(self.OneTouchHandeler(_:)))
imageView.addGestureRecognizer(oneTouch)
imageView.isUserInteractionEnabled = true