UIImageView Touch Event

you can use UITapGestureRecognizer added to the UIImageView via addGestureRecognizer snippets: UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(bannerTapped:)]; singleTap.numberOfTapsRequired = 1; singleTap.numberOfTouchesRequired = 1; [iv addGestureRecognizer:singleTap]; [iv setUserInteractionEnabled:YES]; and – (void)bannerTapped:(UIGestureRecognizer *)gestureRecognizer { NSLog(@”%@”, [gestureRecognizer view]); }

Creating a UIImage from a rotated UIImageView

OK – at last I seem to have done it. Any comments on the correctness would be useful… needed a translate, a rotate, a scale and an offset from the drawing rect position to make it work. Code is here: CGAffineTransform transform = CGAffineTransformIdentity; transform = CGAffineTransformTranslate(transform, boundingRect.size.width/2, boundingRect.size.height/2); transform = CGAffineTransformRotate(transform, angle); transform = … Read more

UIImageView Gestures (Zoom, Rotate) Question

Hope this can be helpful to you, that’s how I usually implement gesture recognizers: UIRotationGestureRecognizer *rotationGesture = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotatePiece:)]; [piece addGestureRecognizer:rotationGesture]; [rotationGesture release]; UIPinchGestureRecognizer *pinchGesture = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(scalePiece:)]; [pinchGesture setDelegate:self]; [piece addGestureRecognizer:pinchGesture]; [pinchGesture release]; Rotate method: Reset the gesture recognizer’s rotation to 0 after applying so the next callback is a … Read more

How to asynchronously load an image in an UIImageView?

The problem is that UIImage doesn’t actually read and decode the image until the first time it’s actually used/drawn. To force this work to happen on a background thread, you have to use/draw the image on the background thread before doing the main thread -setImage:. This worked for me: dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{ UIImage * img … Read more

Passing through touches to UIViews underneath

The UIGestureRecognizer is a red herring I think. In the end to solve this I overrode the pointInside:withEvent: method of my UIView: – (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event { BOOL pointInside = NO; if (CGRectContainsPoint(imageView.frame, point) || expanded) pointInside = YES; return pointInside; } This causes the view to trap all touches if you touch either the … Read more

How to know that if the only visible area of a .png is touched in Xcode

I have created a custom UIButton subclass that behaves exactly as you describe, have a look: https://github.com/spagosx/iOS-Shaped-Button-Swift It’s written in Swift, but it’s easily convertible to Objective-c. The approach is to get the pixel data from the touch point and to access the RGBA values, in this case we read A (alpha) and check if … Read more

How to manage UIImageView content mode?

Please try this code, Hope it will work for you. set UIImageView contentMode to UIViewContentModeScaleAspectFill as below : imageView.contentMode = UIViewContentModeScaleAspectFill; set autoresizingMask of UIImageView as below : imageView.autoresizingMask = ( UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleWidth );