WkWebview inside uiScrollview - ios

I was wondering if you can help me please. I have a wkWebview that has horizontal paging content.
Outside of that I have a scroll view that also has horizontal paging content.
There is obviously a conflict when scrolling and I was wondering what is best to solve the issue.
I want a continuous scroll that when scrolling on the web view that has a content offset less than 0 I want to scroll the parent scroll view to the page before. When the content offset is greater than the size of the content size I want to go to the next page.
I considered using a pan gesture recognizer. However I can’t seem to get it working properly.
When the web view decides to call the parent setContentOffset method how do I make sure that it behaviours like it is paying the content?
Hopefully that makes sense.
Please help.

Related

Add refreshControl to a scrollView with pageControl

As it can be seen in the gif from the link, I was able to add the refresh control to the scrollView but it is only shown for the first page. It still works for the other pages but it is not showing the refresh indicator which might be confusing for the user.
I have tried already a couple of ideas but nothing seems to work.
I am looking for a solution, which either only makes it possible to use the refresh control on the first page and disables vertical scrolling for the other pages or a solution which shows the refresh indicator at every page.
I would also like to disable the diagonal dragging. I added this in case there is a solution which solves both problems.
https://giphy.com/gifs/KfqJnVlwKE9fwFc07R/html5
Help will be very appreciated.
The indicator looks like it is probably added as a child of the scrollview, meaning it is scrolled along with the other contained views, and hence scrolled off-screen.
For an element you want to always be displayed over the scroll view add the indicator as a sibling of the scroll view (i.e. a subview of the scroll view's parent).

Move to Specific Page in ScrollView While Hiding Between Pages - iOS

I have Paged UIScrollVIew with 5 pages.
I have a problem where when I tap a button, I need to navigate from the 1st to 4th page. The problem is that it will show page 2 & 3 during this transition. I just want it to scroll to page 4 as if it were the next page in the scroll view.
Here is a diagram:
Any idea's on how to achieve this?
I think you'll have to reposition your pages within the scroll view to make that happen seamlessly. It probably means keeping track of what pages you've moved and perhaps a state engine that restores your original positions when you leave. It would probably be easier to make each page a subview and add that to your scroller, then you need just change each subviews frame as needed.

iOS UIScrollView with multiple pages visible

I'm having a little issue with scrollview pagination.
My intention is to have 3 pages visible on screen and when I scroll right only on page is scrolled, following the example below, scrolling right will display page 2, 3 and 4 on screen:
However I don't know how to display mutiple pages at the same time, at the moment I have it like this:
Obviously like this is not what I want.
To achieve the desired functionality I tried making the scrollview's frame the size of the page I want (1/3 of the screen width) and setting the clipToBound to NO so the other pages are visible. This indeed shows 3 pages in the screen; however since the scrollview frame is only 1/3 of the screen I can only swipe in that area, I would like the swipe area to be the whole screen width.
You're on the right path. Now you can try manipulating UIPanGestureRecognizer of your scrollView, say, re-attaching it to scrollView's superview.
Alternatively, take a look at iCarousel, it can be perfectly customized to suit your needs.
My solution in the end was the following:
I took my initial approach.
I disabled the scrollview's scrollEnabled property.
Added swipe gesture recognisers to the scrollview.
When the gesture is made I modify the scrollview's contentOffset to move 320/3 pixels to the right or left.

How to create UIScrollView with different page sizes (page snapping, bounce)

I'm trying to create custom vertical UIScrollView which could handle multiple pages with different page heights.
Assumptions:
page height is equal or greater than screen height
if page is taller than screen height, it scrolls as usual UIScrollView – with bouncing on top and bottom
if user ends up scrolling and "page break" is in the middle of screen
if there is no velocity - page snaps to closest
if there is velocity - page changes to one in direction of swipe
I've tried many approaches to achieve this, but I've stumbled upon many UIScrollView quirks, which make it hard.
Problems:
UIPanGestureRecognizer has unreliable method for getting velocity (velocityInView:)
scrollViewWillEndDragging:withVelocity:targetContentOffset: method gives me headache, because it arbitrarily can destroy my attempts to animate setting content offset
I don't know how to achieve bounce in one of the middle pages, I'm afraid i would have to rewrite whole scrolling handling
when I try to override setting content offset when UIScrollView is decelerating, what I get is
my content offset is set
deceleration continues beyond content offset I set
Bonus
I have also tried putting UIScrollView inside UIScrollView as a page, but this approach was also pain in the neck. For example when I was at the bottom of inside scroll, then i scrolled down a bit, put my finger away and quickly grabbed again and scrolled upwards, the outer scroll received touch, which messed up inside scroll presentation.
Does somebody have any idea how to do this? Any tips will be helpful as I'm completely stuck...
Try this. Might help. Based on the Circa news app.
https://www.cocoacontrols.com/controls/rscircapagecontrol

UICollectionView - Horizontal paging with 3 pages visible and 1 in the middle using UICollectionView [duplicate]

This question already has answers here:
UICollectionView: paging like Safari tabs or App Store search
(6 answers)
Closed 9 years ago.
I'm trying to implement same feature like mobile Safari has when scrolling among different pages using UICollectionView. One page is in the middle and parts of other are also visible.
I am struggling to achieve such a behaviour using UICollectionView. There is 1 way I found how to put 3 pages at one screen - make pages smaller and set appropriate insets. But as soon as I set pages smaller and I set paging enabled, pages are not scrolled to the centre as they should. I can also leave paging disabled and use this method in subclass of UICollectionViewFlowLayout:
- (CGRect)rectForTargetPageForProposedContentOffset:(CGPoint)proposedContentOffset withScrollingVelocity:(CGPoint)velocity
In this method I can set exactly where UICollectionView will stop. However, scrolling experience is not as good as it was as using UIScrollview with paging enabled. When I swiped with bigger velocity, several pages were scrolled and it stopped on proposed page. What I want to achieve is same behaviour as normal scroll view with paging enabled - whatever velocity I use, I will get only 1 page more.
Do anyone have any idea how to solve this using UICollectionView?
So you want to make size of a page smaller than the size scroll view, right? Page size is always the same as the size of scroll view, so you have to make the scroll view smaller.
Then there is another problem. How to receive touches out of the bounds of the scroll view?
Override -[UIView pointInside:withEvent:] of the scroll view to check for larger bounds than they really are. Then the touches should work.
In fact I didn't try this myself, I was doing it by placing supplementary view above with desired bounds and override -[UIView hitTest:withEvent:]. Inside I modified the point and called scroll view hit test. This way the touches were handled by scroll view, but their position was wrong. You may want to try combining these two approaches to get correct position.

Resources