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
Related
I am trying to build an iOS app that will have the structure of Facebook's feed:
A vertical collection view that will have cells. Each cell will consist of image and text.
In fact, I am building my app with the help of this video by LetsBuildThatApp (this guy rocks by the way).
Currently, I am able to touch the image and animate it to full width, and also pan to dismiss it if velocity on Y-axis is more than a specific threshold.
What I want to achieve after that is to also be able to pinch/double tap to zoom. Like this:
I searched around and found some great articles on how to use UISCrollView to zoom. [Article1, Article2].
The problem is that I use autolayout to perform animations but these articles either use Storyboards or frames to position the image in the center of the scroll view [or at least this is how I understand it]. And also they don't involve any animations to start with.
Also, I don't want to present or push a view controller onto the navigation controller stack. I would rather animate the view on top of the base view as I do now.
Any idea on how to achieve this?
Thank you in advance!
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.
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.
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
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.