How to Detect the Touch Event of an Uiimageview

Detect UIImageView Touch in Swift

You can put an UITapGestureRecognizer inside your UIImageView using Interface Builder or in code (as you want), I prefer the first. Then you can put an @IBAction and handle the tap inside your UIImageView, Don't forget to set the UserInteractionEnabled to true in Interface Builder or in code.

@IBAction func imageTapped(sender: AnyObject) {
println("Image Tapped.")
}

I hope this help you.

Detect Touch Event On UIScrollView's Content

Your UIImageViews probably have user interaction disabled (which is what they default to). Call the following line on each image view, and your taps should be recognized:

yourImageView.userInteractionEnabled = YES; 

Make sure to do this before adding the gesture recognizer.

I had this exact issue a few weeks ago and this is what fixed it for me.

How to identify a button touch event from other touch events

To know whether UIButton is pressed follow this:

-(void) touchBegan : (NSSet *) touches withEvent : (UIEvent *) even
{

UITouch *touch = [touched anyObject];
UIView *touchedView = [touch view];

if([touchedView isMemberofClass : [UIButton class])
{
//do something when button is touched
}
}

How to recognize a touch event on UIImageView while animating in ios using objective c code?

Add this method & load this method on viewDidLoad instead of loading SwipeImages on viewDidLoad

-(void)addTimer
{
aTimer=[NSTimer scheduledTimerWithTimeInterval:15
target:self
selector:@selector(SwipeImages)
userInfo:nil
repeats:YES];
}

Then your viewDidLoad looks like

scrlNo = 0;

imgslide.userInteractionEnabled = YES;
[self addGestures];
[self addTimer];

And Edit SwipeImages to this,

- (void)SwipeImages
{
if (scrlNo==1) {
imgslide.image = [UIImage imageNamed:@"promo_banner_2.png"];
scrlNo=2;

}else if (scrlNo==0) {
imgslide.image = [UIImage imageNamed:@"promo_banner_1.png"];
scrlNo=1;
}
else if (scrlNo==2) {
imgslide.image = [UIImage imageNamed:@"promo_banner_3.png"];
scrlNo=3;
}
else if (scrlNo==3) {
imgslide.image = [UIImage imageNamed:@"promo_banner_7.png"];
scrlNo=0;
}
else if (scrlNo==4) {

}
}

How to get touch location when clicking a UIImageView?

override func touchesBegan(_ touches: Set, with event: UIEvent?) {
if let touch = touches.first {
let position = touch.location(in: imageView)
print(position.x)
print(position.y)
}
}


Related Topics



Leave a reply



Submit