How to render non-zoomed overlay over image in UIScrollView - ios

My plan is to render a custom waveform inside an UIScrollView (to allow user to pan and scroll through the waveform). But additionally I want to render additional non-zoomed information on top of the waveform (like play position marker, time, ...)
So I have a static UIImage that is the pre-rendered waveform, and some small bits that i have to render on top of it dynamically (I don't want the position marker or text to bee zoomed on the waveform).
I have read that UIImageView is the most efficient way to render a simple image (Most efficient way to draw part of an image in iOS), but that is not sufficient for me because i have to render something on top of it. Or is this somehow possible?
I dont see a way to use the UIScrollView for now, because it zooms everything inside right? But as mentioned, I need only the image zoomed, but the additional data non-zoomed.
Can I implement this using UIScrollView? Or do I have to implement a custom view that takes care of zooming and panning by itself?

If I understood your properly, you need to zoom one view(UIImageView) and prevent zooming another view (UILabel, for instance). So, you are wrong that Scroll View zoom everything inside it. UIScrollViewDelegate has method
optional func viewForZoomingInScrollView(_ scrollView: UIScrollView) -> UIView?
It should return view that should be zoomed. Hope, I helped you.

Related

Use NS[UI]ScrollView to manipulate projection

I have a simple metal setup which draw image in the middle of MTKView. I wish I could add pinch zoom and other functionality as we have in scroll views, so i can zoom image and move it around with some thresholds.
I also don't want to implement it myself since my app will live in both Mac OS and iOS and this is twice more code to support and write.
Is there a way I could use default scroll view controlls to manipulate my projection? I mean set scroll view somehow on top of my view and get some data in delegate manner or whatever.
Any help would be appreciated!
You may want to try Metal2DScrollable sample code. The idea is that:
place MTKView behind (not a subview) UIScrollView,
Place dummy content view as a subview of UIScrollView
Make the dummy content view to be the target of zooming
Set up UIScrollView properly such as contentSize, contentInset etc.
Make both UIScrollView and dummy content view to be transparent
Calculate transform from dummy content view's bounds -> MTKView's coordinate -> device coordinate
Apply that transform when rendering with Metal
So, MTKView is not in the UIScrollView, but this tricks fools user's eyes.
https://github.com/codelynx/Metal2DScrollable
The same technique may work with macOS with some tweaks, but I haven't tried.

Drawing a graph within a UIScrollView

I am exploring the idea of drawing some custom primitives (using CGContext) on a view that is scrollable and larger than the phone screen width.
The idea would be to use the "power" of a UIScrollView by programmatically scrolling the content of the view as the content is added and decouple in this way the scrolling handling (and general UI interaction with the view) from the content drawing.
Is this a feasible approach in iOS?
Yes it is. The easiest approach AFAIK would be to add a UIView onto the UIScrollView. You would then draw on that UIView instance - after drawing another part of your graph/image you would need to inform the containing scroll view, via a delegate for example, that it needs to update its contentSize. This would of course be the size of the UIView upon which you drew. The update is needed, beacuse it seems that you may need to increase your drawing area size as you do it.

How to zoom on UIView

In my iOS app I want my users to be able to zoom in on the screen. My main uiview contains several subviews which contain images. I want my uipinchgesturerecognizer to either change the scale, or ideally use some "zoom" rather than scaling each subview.
Please and thank you.
This can be accomplished with UIScrollView. First create a scroll view as the base of your view hierarchy, putting your previous container view as a subview of the scroll view. Set the delegate of the scroll view to self and implement the delegate method viewForZoomingInScrollView, in which you should return the view that will be zoomed in (your original container view). This will allow the user to pinch and zoom your original UIView.
It's hard to provide advice on this without having a clearer view of what exactly you want to achieve.
Can you include a link to a sketch? For example, do you want the individual subviews to remain the same size but the layout to change ? Do you want the individual subviews to resize but their contents to be upscaled?
If you simple want to treat the subview as (basically) a single image which just happens to have other images in it, then maybe it would be better to render it as one and then scale that?

Zooming CALayer blurs the view

I want to zoom a CAlayer placed on UIView, and this view is on UISCrollview. I'm using scrollviews delegate methods for zooming. It zooms but it blurs. How to remove blur and improve zooming?
I have tried with CATiledLayer but I don't want to show tiling effect. So how can I improve zooming using CALayer?
I had a similar experience when zooming in content. When a UIScrollView is zooming, it takes a snapshot of the View, and zooms in on that picture. This is the reason it gets blocky when zooming. When the zooming/panning is complete, use the delegate to re-render the content according to your zoom level. The content then should be 'crisp'.
Warning: do not zoom in too far, the memory used by the snapshot will soon be larger than your available memory.
I didn't use images, but CAShapeLayers and paths. I put together a demo project and explanation here : http://simplicate.weebly.com/1/post/2013/06/fixing-blocky-paths-in-ios.html
I hope that helps.

Pan and Pinch a UIImageView within a ScrollView

I have created a small app using a ScrollView w/ paging and a series of UIImageViews each representing a page. It acts similar to the Photos.app.
I want to be able to pan and zoom individually for each image (page of a scrollview).
What would be the most sound approach to do this? Should I replace the UIImageView page with a scrollview with a UIImage inside it? I would then have a main scroll view where each page of the scrollview had a scrollview with an image inside it that could be pinched,etc.
It seems like a messy approach. I am looking for a clean approach. Any suggestions?
Well, as far as I know the approach you suggest is the way it is done. I have used this to create a PDF viewer and once everything is in place it doesn't feel too messy.
You might want to use CATiledLayer as your inner (per-page) scrollview's layer (instead of CALayer) if these images you have are really big (which could well be the case since otherwise zooming in on them would not bring you much but pixelation, but this is just an assumption on my part).
Checkout UIPageViewController. This controller manages a view controllers for each page and transitions between them using effects like page curl or scroll.
In your case you would create a view controller that manages a scrollview for zoom & pan for each page.

Resources