i am working on a project in which i have added a UIimageview to show an image selected by user. Now requirement is that if user want to crop an images it can touch the image according to crop requirement. when user cropping the image a line should draw at place where user has touched. i know that UITouch class will use for it. But i am unable to do it.
A couple of possible solutions.
1) Create a custom UIView that contains a UIImageView as it's subview. Make the UIImageView be the same size as the custom UIView. Then add code to detect the touches on the custom UIView and draw the lines on top of the UIImageView subview.
2) Create a custom clone of UIImageView that draws the image first as the 'background' and then detects the touches and draws the lines on top of the image.
Also make sure you have userInteractionEabled set to YES on the view receiving the touches.
Related
I am creating a notes application in which user can add any number of text views and the views will have borders (like image below) so that a user can resize it.
I am thinking to create a UIBezierPath, but I don't know how to add gesture recognizers on UIBezierPath.
I have a UITableView with rows.
Each row has a small UIImageView aligned to the right (a "bookmark" icon)
The UIimageView has a UITapGestureRecognizer associated.
cell.favoritedImageView.userInteractionEnabled = true
cell.favoritedImageView.addGestureRecognizer(gestureRecognizer)
The problem is that to actually tap it with the finger (in a real device), you have to use the tip of the finger and be very accurate, because the image is small.
If you miss tapping the imageView, the cell is tapped (didSelectRowAtIndexPath) and you end up executing a show-segue to another view, so you have to go back and try again (not cool)
Question: what is the best way to solve this? I want it to be easy to be tapped.
I have some ideas:
Create a larger image with transparent surrounding (ie: crop out with transparent background) -- downside is that I also use this image in other views, in which is not tappable, so I'd have to create two versions of the image
Put the image inside a UIView and make the UIView big and tappable instead of the UIImageView
Add padding to the UIImageView (will this work? or the padding is not recognized in the UITapGestureRecognizer?)
Per your own suggestion, you should create a transparent view that is much larger and attach the UITapGestureRecognizer to the view and then nest your smaller image within the view. That way appearances are the same, but you handle a much larger area for the tap to be recognized with selecting the cell.
I ran into a problem while building a map app. I'm trying to do the following:
add an animated PNG sequence as overlay to the map so that it appears to be "on the map" while the user changing the zoom, rotation and pitch of the map.
on top of that PNG sequence I would like to show a custom pin image, using MKAnnotationView.
So far, what I've been able to do is:
Load PNG sequence into an UIImageView and animate them.
add the UIImageView to the MKMapView, using addSubView:.
Detect changes to the MKMapView and update the position of UIImageView accordingly
However, if I start adding MKAnnotations to the MapView, they get added below my UIImageView (see image on the left).
Is there a way to add them on top of the UIImageView (see image on the right)?
?
I have got a MapView with some custom MKAnnotation, MKAnnotationView which I use to create nice custom callout.
Anyway, for my main Annotation Pin, I use some nice image of pins with a pre-rendered shadow on their left.
However, I would like the annotation not to get selected when the user touch its shadow. Because when their are a lot of them, the shadow of one can overlap another, and the wrong one gets selected because the shadow gets touched.
I have tried to use a separate image for the shadow and put it in a UIImageView inside the MKAnnotationView but it does not change anything, even if I put enableUserInteraction = NO.
any idea?
Make your MKAnnotationView the size of the image excluding the shadow. Change it's frame so that it encompasses the part you want it to receive touch. The shadow should exceed this frame, but shouldn't be cut off.
I have universal app. In that app I need the background image to be centered or stretched. That way when I rotate the device or switch it the image displays correctly.
Here is my code in viewDidLoad:
self.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:#"tux.png"]]
Can anyone tell me how to accomplish this?
I think you can't easily make it centered with backgroundColor. You may:
Stretch it before setting the image as backgroundColor, see How to fill background image of an UIView.
Create a customized UIView subclass and draw the background image yourself by overriding drawRect: method;
Or add a UIImageView to you view as the background. See "UIView Class Reference: Alternatives to Subclassing":
Image-based backgrounds - For views that display relatively static content, consider using a UIImageView object with gesture recognizers instead of subclassing and drawing the image yourself. Alternatively, you can also use a generic UIView object and assign your image as the content of the view’s CALayer object.