Layout for 3 uiImageView side by side using swift - ios

I want to create a control for ios 8+ where we have 3 images. In center image in big and left/right images are small.
I have to create some code in swift, using Stack Layout but it will not work in iOS 8 as it is available from ios 9. So need to change this. What should i use to keep images together (left and right bottom)?
Also another problem i have is, i need pan gesture on only big center image not on the small left and right image. So when i touch the big image i can move all three around the screen. Currently it if i touch any of 3 all moves.
Functions:
small left/right image: Act as button for running a swift function
middle image: on pan gesture drag all three around screen

You have 3 choices to create an image slider according to your requirement.
Using Scroll view (UIScrollView)
Using Collection view (UICollectionView)
Using Page Controller
Here are simple/basic logic, how and what you should use to achieve sliding image.
Using Scroll view (UIScrollView)
Add three images in scroll view with equal width
Set Height of middle image, according to your requirement (bigger than other)
Set width of any one image (probably middle) equal or around equivalent percentage (80% equal) to device screen using AutoLayout constraint.
Scroll view automatically scroll horizontally according to horizontal content size. You don't need to add Pan gesture.
You can also enable paging of scroll view.
Using Collection view (UICollectionView)
Add collection view with three (static) cells or single dynamic (You need to choose how do you want to update this feature in future. If you choose single dynamic cell then you can easily add more images in slider by adding its data into datasource variable, in future.)
Enable horizontal scroll only in collection view.
Update (make it bigger) Image height in data source method using index path for item (indexPath.item == 1).
Collection view have pan gesture also. You don't need to implement it.
You can enable pagination also.
Note: Set image/cell width equal to device screen or equivalent.
Using Page Controller
Here are nice reference tutorials, "How to use Page View Controller"
How To Create UIPageViewController Using Storyboard
How to Use UIPageViewController to Build Tutorial Screens
I do not recommend this option (Page view controller) but you have provided complete details about scope of your requirement (view controller level or it is simple child view slider), so this is an option to image slider also.

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.

Slide view from bottom in and blur rest

I want to have a view sliding in from the bottom, but the height of this view-element is just about the half of the screen height. The upper part of the screen should blur out.
I am very new to building ios-Apps and I wonder what is the best approach to do this.
Should I use viewElements in the same ViewController and just let them slide in etc. or is there some build-in functionality which I can use?
You can do two things:
define a custom interactive viewcontroller transition, that way you can add a blur view in the background and bind the offset of the scroll up to the blur effect to animate the change.
(I think this is a lot easier to implement, but less reusable) embed a container view in your viewcontroller, add a pan gesture recognized on the view and as you pull your finger up, animate e.g. the bottom constraint's constant to move the view up and do the same with the background as described in step 1

Custom Page Control with Paging Scrollview

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.

Custom Collection View Layout like Chanel app

I'm trying to do a custom layout like the Chanel app you can find the app in the Appstore.
https://itunes.apple.com/us/app/chanel-fashion/id409934435?mt=8
I know they are using an UICollectionView, but no clue how to start.
The interaction feels like a tableview mixed with a paginated scroll. When you scroll the elements grow, and the first element position itself at the top.
Start with dragging & positioning just one UIView. See UIGestureRecognizer docs and look for existing examples of movable views. You'll need an UIPanGestureRecognizer to move the view.
Resize the view depending on its Y position.
Create & position an image inside that view depending on the view size using a couple autolayout constraints.
Note that Chanel app has different constants for these constraints. With a minimum view height, one image's top is 80% height, for another image it's 90% height. Make sure you can manipulate constraints from code (I think it's a good idea to create everything from code there, XIBs are not very flexible).
Make the view "anchoring" to certain points (e.g. top = -75%, 0%, 75%, 90% from what I see in the Chanel app) when you stop moving it. Just find the nearest one and animate the view to it.
Once you did it with 1 view, move all your work to an NSView subclass (if it's not yet there) and create a collection of these views.
You can create UICollectionView, but I'd rather do it with a simple NSArray: I actually don't see a reason to use UICollectionView here; it's a very simple structure. Anyway, you write your own gesture recognizer (don't you? I can't see another way) - so what's the point to use UICollectionView? If you want to expand the app functionality some day, UICollectionView will unlikely help you with that. Well, it's my hypothetical approach, you can find another one while working on that.
Position other views while you're moving an "active" view. Do it by hand, without any UIScrollViews.
Write a function that reflects the Y position of the "neighbor" views while you moving one. It should "slow down" to the bottom of screen.

How do I create a custom UIView that slides down or up from behind a UINavBar depending on scroll direction in objective-c?

Currently building a store app. I have a collection view that displays clothing images with their prices and title. I'd like users to be able to filter and refine results and change the layout of the page using a special bar that will slide down and plot itself just underneath the UINavBar.
This is what I want to do:
User starts to scroll down.
Slide down nav bar sized custom view at desired speed from behind UINavBar.
User starts to scroll back up
Slide up nav bar sized custom view at desired speed from behind UINavBar.
Custom view should be opaque
Custom view shouldn't effect the controller view and sit on top of it when visible.
Part of my hierarchy:
UINavigationController -> UIViewController -> UICollectionViewController
All above will be taking place in my UICollectionViewController.
Futher info:
Since this is something I'd be doing often I'd like to learn and understand how to do this properly, however I don't mind using ready made solutions.
Image below may help..
I look forward to you responses.
Kind regards
Adding a basic pull down here is very easy steps.
I have used here in this example a UIToolbar to slide in & out
UPDATED
The video mentioned here is updated today with added colours to the slideIn toolbar.
UPDATED : 1
kindly try the GTScrollNavigationBar as described here in this post of stackOverflow.
Another option could be to add a UIPanGestureRecognizer on the scroll view. You could use the translationInView method to know how much distance to move your view.
First, it would be better that you change your view hierarchy to
UINavigationController -> UIViewController-> UICollectionView & custom view
In your current code, have you added the collection view as a cell in the tableview?
Well, since the collection view is inherently scrollable, this is not necessary.
besides, if you add your custom view to the tableview or the collection view, the custom view will scroll alongside with the scrollable view, which, i bet, is not what you want.
so what you may do is to:
1. add the `custom view` to the view of the `UIViewController`
2. add also the `collection view` to the `UIViewController`
3. implement `UICollectionViewDelegate`, `UICollectionViewDataSource` for the `UIViewController`
4. implement 'scrollViewDidScroll' in 'UIScrollViewDelegate' for the `UIViewController` to detect scroll action
5. get scroll direction as indicated here:
Finding the direction of scrolling in a UIScrollView?
6. when a scroll is detected, set the desired frame of your custom view in [UIView animateWithDuration:animations:], and adjust speed by adjusting the duration of the animation.
7. Done!
well, just in case.... you can set the origin of the frame as negative to move the custom view outside the view of the UIViewController

Resources