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?
Related
Instead of the standard dots that Apple provides for a page control, I want to have something like this. However I don't want it to be in an infinite loop were you can circle around. All I care about is the scrollable text on top, not the parallax image.
Currently I have a paging scrollview that contains three view controllers so my custom page control will have only three words: Main, Today, Settings.
The way I see this being built is the following:
Subclass UIView and insert three UIButton's and evenly space them. The title of the buttons will be Main, Today, Settings.
Insert this UIView as child of scrollview (or maybe not)
Make UIView the width of the iPhone screen
Not sure about here now -> as you scroll the scrollview shift the UIView on and off the screen so that the UIButton will be centered in one of the view controllers in the scrollview.
Am I on right track or does anyone have a demo to this?
Yes. You are on right track. You can use scrollView for this exact purpose. You have to make use of scrollViewDelegate methods for this. The below link will explain you how to do that.
How to make Paging with scrollView.
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.
I'm using a UICollectionView (with horizontal layout) to manage a collection of images. The view controller that manages the collection view has the bottom toolbar visible with a play button to start a slideshow of the images in the collection. My question is what is the best way to implement a slideshow that involves a collection view? My initial thought was to try to make the collection view changing the visible cells with a UIView transition (transitionFromView or transitionWithView) with a cross dissolve option but I didn't get the effect I was expecting (maybe something wrong in my code). The other idea I had was to simply add a subview to the collection view to handle slideshow. This subview would have access to the data source and be able to iterate through the images. Don't know if this last option is a good way to approach the problem. Anyone has ever tried this and/or what would the recommendation be to solve this problem?
My idea is no need of collection view. In scrollview place imageview which display images. In timer Change the offset of scrollview. so it looks like automatically images are changing as like slide show.
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.
I've got a scrollview that allows the user to scroll between different pages and then tap on one to have it expand so that they can read the page in full, a little like how one changes tabs in Safari on the iPhone. Changing the frame size of each sub view is a bit of a pain when rotating as the scroll position is getting lost as the content size of the sub view has to change too. I was wondering if there was a more effective way of
resizing the views for entering 'viewing' mode or rotating the device.
The solution to your first problem is when you want to expand the view, pull it out of the scrollView then add it to self.view.subviews with an appropriate frame, then animate the frame to fill the screen. When done with it do the reverse, shrink it, then when its back to the appropriate size stick it back in the scrollView.
If for some reason this does not work - the scrollview is showing other stuff that gets moved when you remove the view, then instead of just removing your view from it, create a simple UIView of the same size as the view you will expand, and essentially replace the view you pull out with the "placeholder" view.