How do I make custom control based on scroll view with animations? - ios

I have made numerous controls like pickers that had static elements. You could scroll it and pick the number like in standard picker.
But now I need to make a picker that changes its elements based on their position. Here is the image:
I want elements to shift color from white to another color slowly while they are being swiped, and change the size while they are moving. E.G. the central element will be filling with white and getting smaller size and next element should increase in size and fill with other color.
It should also be dynamic, if I go halfway and decide to swipe back, it should work as intended, returning the last central element to its position. So for each pixel I scroll the elements should change.
How do I attack this?
I know the basics, how to call delegate methods, I have this handled, only question is how do I animate this?

I managed to do this with scrollViewDidScroll delegate method, as it gets triggered even if the scroll view was moved 1 pixel.
I set up collection view with cells, and have it send scrollViewDidScroll to each of those cells. Based on the data those cells adjust themselves via CGAffineTransform (for size) and my own written functions that provide relevant color for each offset.

Related

How to center content inside collection view in exact center of shown ring view while scrolling horizontally (iOS)?

I want to set center the content inside a UICollectionView according to ring image in the center of the whole screen. Please check the image below. Any Suggestions?
The function you need is this one... https://developer.apple.com/documentation/uikit/uicollectionviewdelegate/1618007-collectionview
This function is called by the collection view when the user finishes scrolling. It provides the content offset of where the collection view will stop scrolling. (The proposed content offset).
You then need to take that offset and work out the nearest offset to place your cell in the middle of the screen.
Something like, find the item that will be closest to the middle. Work out how far away from the middle it is so you know how much to shift it by. Then apply that shift to the proposed content offset.
This will allow your collection view to decelerate naturally but always stop at the point that you want it to stop.

UIImage - Infinite Scrolling Background

Does anyone know how to do something like that?
I would like to get a continuous scrolling of the image.
Example: https://vimeo.com/262632459
Here is a simple way of doing it.
Set it up
Create the image you want to scroll in the background. You need to make it minimum as wide as the widest screen you want to support.
Place two instances of the image you created next to each other inside a regular UIView.
Place the view on the screen with the x position at 0.
Animate
Animate the view repeatedly forever, moving the x position from 0 to -width. The width is the width of your image (just the width of one instance). Note that since you want to pull the view left, you must pull x in the negative direction.
The image will now slide left until the second instance x is at 0. At this position the animation will start over, moving the view one whole image size to the left. This movement will not be noticeable since you use two identical images.
You need to use scrollview or subclass of scrollview and in that scrollview add your image you want to scroll.
override scrollViewDidScroll delegate method of scrollview, here you can control the animation (how much user can scroll or other behaviours)
https://developer.apple.com/documentation/uikit/uiscrollviewdelegate/1619392-scrollviewdidscroll?language=objc
And if you want circular image(when image reach to last start again) add two copy of same image, One at zero position, before your acutal image and one at last position after actual image and as soon as image reaches to last remove the font image and add in the last, and if user scrolling in right direction remove the last image and add in front.
In scrollview add three imageview and keep adding and removing from the front and last based on the scroll direction. In scrollViewDidScroll you will get direction of scoll based on change in x value

Creating an animation such as iOS 8 Weather App

I want to create a view in which I like to have animation such as the one present in iOS 8 Weather app.
I try to explain more what I have done. If anything is incorrect please guide me.
In the top I put a label for the temperature. (The big one)
Below that label, I put another label to show some text. In the Weather app, there is the horizontal scrollview showing the hourly forecast.
Next is the Table view.
What I want to achieve is that when I start scrolling, the first label disappear smoothly and the second one go to top of the screen and the TableView stretches to show more content.
When I scroll back to the top, I want the whole process to revert.
What is the best way to do this?
I've recently re-created the iOS8 Weather app's scrolling effect for an app I'm creating.
The complete code is too long to post here but for anyone who's interested, I've put it on GitHub. You can download and run the project to see how it looks. Improvements to the code are welcome:
UIScrollView with masked content.
It works like this:
You have one scrollview (the size of the screen), which contains a subview (the mask) which in turn has a subview (the content). We also add a large label to the top of the screen (in the Weather app, this displays the temperature).
Then you use the scrollViewDidScroll delegate method to keep the mask fixed to the screen as the user scrolls. You also use this method to stretch the mask upwards at first.
Fixing the mask to the screen means that the mask's subviews (our content) also becomes fixed. But we want it to scroll, so we do the opposite to the content of what we did to the mask (again, using scrollViewDidScroll).
We need the mask to actually behave as a mask, so we set clipsToBounds = YES on the mask.
Finally, we use the scrollview's offset during scroll to move and fade the big label at the top of the screen.
To make it behave exactly like the iOS8 Weather app, we need to also do the following:
Cancel any scroll touches that happen above the mask, i.e. over the large temperature display.
Ensure that the initial scroll that moves the temperature display is completed programatically if the user doesn't complete it.
Add a sideways-scrolling subview which is anchored to the top of the mask.
I haven't done these yet, though.

Changing VoiceOver's scrolling/paging distance on a UITableView

I have a screen in my app that consists of a UITableView with another opaque view overhanging on the top (which is also interactive). The content offset is set correctly such that the entire tableView is visible to a sighted user.
However, when using VoiceOver and paging up/down with three fingers the default scroll distance will place part of the tableView under the overhanging view, and thus prevent VoiceOver from reading part of the tableView[1].
Is there any way to change how tall a "page" is when using VoiceOver?
[1]: I know that there are still ways to cycle through all the elements, etc, but it's far easier and more discoverable for partially sighted users to skim over elements with their finger.
I think you are looking for this: https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UIAccessibilityAction_Protocol/index.html#//apple_ref/occ/instm/NSObject/accessibilityScroll:
Re implement that method and scroll the amount of pixels you require instead of a whole page

Fast custom animation using CADisplayLink causes stroboscopic effect. How to avoid it?

Scenario:
Horizontally scrolling UIScrollView with reused page views (so that there are only few page viewcontrollers which are being reused similar way like UITableView cells). So that they are able to be updated with new content and reused I need to know exact position of UIScrollView's content view (offset). This works great.
Now I need to implement custom scrolling animation - I mean to programatically move the content view, so that user touches some buttons, and the scroll view scrolls to desired position with this custom animation. The movement can be very quick and very far. I can not use Core Animation for this, as I could not track position during animation (CA reports you only start and end of the movement). So I decided to use CADisplayLink, and calculate each UIScrollView content for each position. This works great too.
The only problem is, that sometimes I see stroboscopic effect - say I am moving the content to the right, and it looks like it is moving to left. If I look at builtin animation within UISCrollView using setContentOffset:animated:, the animation is smooth and nice. Does anyone know, how to get rid of this stroboscopic effect?
Most likely your issue is that timestamp is a double and you're assigning it to a float
Floats have 7 digits while Doubles have 15-16 digits.
So in other words you're experiencing data loss. By using double you should see a silky smooth animation.

Resources