annotate buttons onto uiimageview (like mkmapview without MapKit) - ios

I have a UIImageView set on top of a scrollView. The image is a map, and I need to annotate buttons across the map to corresponding locations (very specific to the region). The buttons are visible, and they pan and scale accordingly when scrolled/zoomed, this works great. The issue is when the buttons are rendered on different screen sizes, the buttons are placed in different spots since auto-layout puts them the same distance from the edge of the screen, but the image has a different bounds property and is bigger/smaller depending on the device.
I've considered creating an MKMapView with a custom overlay of this image, but I was hoping to keep it super light-weight and avoid MapKit all together.
Any suggestions? Clarifications are fully encouraged :)

You should add buttons as subviews on imageview so that buttons transform in the same way as imageview does.

Related

Horizontal UIScrollView and multiple thumbnail images in iOS?

I need to create a horizontal UIScrollView which to hold hundreds of thumbnail images, just like a slide of thumbnails and a UIImageView that will hold the center image of UIScrollView
For example, there will be 6 thumbnails showing in a single screen, each of them are horizontally adjacent to each other.
My problem is that I don't know how to make a horizontal UIScrollView to hold the multiple thumbnails which showing at the same time and then display the center image to the Topview image?
A sample photo is as below. See the bottom part of the screen.
Screenshot Image
There are many ways, here is one:
The top part
Option 1.1
The top image views can be handled by a UIPageViewController wrapping something to the effect of ImageDetailViewController
Option 1.2
The top is a UICollectionViewController and the large top images are UICollectionViewCells. You can use UICollectionViewFlowLayout with a horizontal scroll direction and pagination true.
The bottom part
Option 2.1
The bottom part should be a UICollectionViewController as you may need to overflow off the screen and it is fast and scrolls horizontally.
Option 2.2
The bottom part can be a StackView created with items programmatically and filled in with a spacing you want. Add a UIGestureRecognizer to detect touch down.
Recommendation
Top: 1.1 - Use a UIPageViewController
Bottom 2.2 - Use a stacked view with a gesture recogniser over the top
Assuming you want them to pan over the bottom, I would say 2.2 is the option, but slightly harder.
So what this looks like is a UIPageViewController, with a floating thumbnail on the bottom to scrub.You can just implement a simple ImageViewer (UIImageView inside a UIScrollView to allow zooming etc).
This will give left/right scroll for free.
You will layout the thumbnails on the bottom inside a stack view and it is better to handle one giant gesture recogniser on the bottom so you can keep it continuous without lifting finger. You will just have to get the coordinates or view that is translated inside the touch.
Rather than go into code because there will be a few different classes I will try to give a topographic explanation.

Custom UISlider with pips ios

Wondering if the above can be created using UISlider? If not, what other ways can this be accomplished?
You can set components of a UISlider, such as the currentThumbImage ( see: "Appearance of Sliders"1).
However, it is almost certainly easier to just re-implement a slider for this much customization. Simply use background UIImageView with the scale image, and then add a separate UIView (or UIImageView) for the arrow. Finally, attach a UIPanGestureRecognizer to the arrow view to allow a user translate the view vertically.
You can change a lot in the appearance of a UISlider like setting the thumb to a red arrow. You can also replace the background image with the inches ruler and with different rulers for the different device types and display sizes.
The one thing that I don't see is that you turn the slider to work vertically. I know them only working left to right.
If I'm right, your only chance is to have a ruler as background image and a view that contains the arrow and a label with the actual value. That whole view can be pawned and tapped using Gesture Listener.

Make a small UIImageView easy to be tapped

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.

Adjust UIView inside UIScrollView MultiOrientation

In my app i receive a image dynamically.
After process the image i need to add some views on top of that image (after the user can drag this views).
To accomplish that, i put the image on UIImageView and add the views on that UIImageView.
According on its dimension i need to adjust the UImageview to fit the screen, but maintain the original scale.. The user can also make zoom.
The main problem appears when the user rotate the device. I need to adjust the UIImageView and it´s subviews correctly to maintain their relationship with the image.
For example in portrait:
And Lanscape:
My doubts:
Correctly adjust the UIImageview´s size, maintainig it´s original scale.
Adjust the subviews to maintain their relation position to the UIImageView.
Thanks in advance

Is there a way to set different frame sizes for different layers in a UIScrollView?

Right now I have a UIScrollView and a semi-transparent top and bottom bar which go over it. The UIScrollView contains a large UIImageView that is pannable and zoomable.
I want to be able to toggle the image and darken everything around a certain part of the image, but have the transparency mesh perfectly with the top/bottom bars which are semi-transparent. Since the content is scrollable/zoomable, if I darken the image itself, anytime that part goes under the top/bottom bars it will double darken.
I tried to solve this dilemma by creating a smaller UIScrollView that sits nested between the top and bottom bars, and sending zoom/pan commands to it in an attempt to mirror the UIScrollView below it, but that didn't work too nicely. It was a nightmare trying to sync the animations (I tried copying over the zoomScale/contentOffset in zoomDidScroll, sending the zoom/pan animation to each UIScrollView individually, using KVO, etc).
Is there any way I can set different frame sizes/cut-off points for each individual layer? Or perhaps each UIImageView subview? I'm open to any other proposed solutions as well, this has really been driving me up the wall. I appreciate the help.
What it's like before toggle:
What I want after toggle:
Why not cover the "center" part with another semi-transparent view to match the tool bars, then use a mask on the layer to make the part of it you wish fully transparent?

Resources