Is there a way to get the position of the scrollIndicator in a collectionview? - ios

I have a CollectionView with horizontal scroll direction in a UIView. I want to hide the scroll indicator and draw a line in its place. I am trying to retrieve the y coordinate of the scroll indicator so I can use it to position the line on top of the scroll indicator. How can get the y coordinate of the scroll indicator in my view?

a scrollview by default contains two subviews. the first is an imageview representing the horizontal scrollindicator and the second is an imageview representing the vertical scrollindicator. so:
let horizontalScrollIndicatorY = scrollView.subviews.first!.frame.origin.y
print(horizontalScrollIndicatorY)

Related

Animate a View to a selected cell in collectionView or tableView in scrollView

I know the title is not explanatory, but the following image will explain what I want to achieve.
Is there any way that I can complete this task?
What you need to do is…
Find a common superview to both your view and cell
Calculate the start position in the superview
Calculate the end position in the superview relative to the cell
add the view to the superview at the start position
Animate to the end position
add the view to the cell, keeping it in position
You'll need to use
convert(_rect:, to view:) -> CGRect
to find A view's start and end position in the common superview

how to change direction of scrolling in UIScrollView?

I have a horizontal scroll view with fixed height .my scroll view, scrolls from left to right but I want to scroll from Right To Left . how can I achieve this?!
this is how I created my Horizontal scroll View:
I've scroll view leading and trailing align to parent, and height = 50, inside my scroll view there is a view with equal height and width to its parent, but the priority of equal width is low, so it can scroll horizontally!
the answer was in this link
I had to add these lines to my code in swift 4:
myScroll.transform = CGAffineTransform(rotationAngle: .pi);
subview.transform = CGAffineTransform(rotationAngle: .pi);

UIScrollView Bounces To Either Top Or Bottom

I have a UIScrollView for which I have a UIView which is the subview of the scroll view , the UIView has a lot of other subviews and I am getting the height for it dynamically after adding the subviews , this is my piece of code to add the view to scroll view
CGRect frameOfView = CGRectMake(0, 0,Get_Bounds.width, globalYPosition);
self.parentProductDetailView = [[UIView alloc]initWithFrame:frameOfView];
I am first initialising the view this way and then after adding all subviews I am doing this,
frameOfView.size.height = globalYPosition;
[self.parentProductDetailView layoutSubviews];
self.parentProductDetailView.frame = frameOfView;
[self.productDetailScrollView addSubview:self.parentProductDetailView];
self.productDetailScrollView.contentSize = CGSizeMake(0, self.parentProductDetailView.frame.size.height *1);
But my scrollview does not scroll properly it either sticks to top or bottom.
Here globalYPosition is the sum of height of all subviews added to parentProductDetailView
The procedure you used seems correct. No matter the subviews your scroll view should scroll properly by simply using a larger content size then its frame size.
The scroll view may stick, snap to some points if paging is enabled which is what is happening in your case. If the content view is larger then 1.5th of the frame size then the scroll view will snap to top/bottom or left/right. If it is smaller then it will only snap to starting position.
This may be very useful for situations like having a side menu that takes a part of a screen but in your case you should simply disable the paging and scrolling should work fine.

Multiple UICollectionView

Hi Is it possible to create a Collection View with different scroll direction?
First section should scroll Horizontally and the second section will scroll Vertically.
I'm planning to create an app that shows the featured item image(array) in the first cell and user can swipe horizontally to see the next image and the rest is 2 cell per row and will scroll vertically.
EDIT: It should be treated as 1 view (for scrolling purposes)
Yes. You can simply create 2 different collection views. One will has horizontal direction. Another one will has vertical direction.
Update:
If you wanna move out the top collection view. I'd recommend you to implement UIScrollViewDelegate on the second collection view (UICollectionView is subclass of UIScrollView) and when user starts scrolling just moving top collection view out.
yes you can add a first collection view on view controller and add a header to collection view and add a another collection view on that and manage it with tag call the delegate method on the base of tag .
While scrolling, do you want the top part (IMAGE) to be scrolled or remain there at top?
If you want it to remain at top than create 2 collection views separately. One horizontally scrolling other one vertically scrolling.
If not then create one collection view (which moves both horizontal and vertical) with items/2 + 1 sections. First section will have multiple items and have another layout so that it will move horizontally. And the following sections will have 2 items but fit to the screen so that wont move horizontally.
Ya, its posible to create two UICollectionView, first is top and second is bottom. set the scroll direction flow horizontal or vertical.
your design is created below,
select the UICollectionView then see right side, select the Attribute Inpector set the scroll Direction Horizontal or Vertical.
GreenColor is one UICollectionView, GrayColor is second UICollectionView. < and > is UIButton
Use the scrollview delegate methods its scroll top side
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
GreenView.hidden = Yes;
//update the GrayView frame its helpful
/* CGFloat x = self.mainCollectionView.contentOffset.x / self.mainCollectionView.bounds.size.width * SM_IPHONE_THUMB_CONTAINER_SIZE; // cell width + spacing 48 + 8
CGFloat y = 0;
CGPoint contentOffset = CGPointMake(x, y);
self.thumbsCollectionView.contentOffset = contentOffset;
CGFloat x = self.thumbsCollectionView.contentOffset.x / self.thumbsCollectionView.bounds.size.width * SM_IPHONE_THUMB_CONTAINER_SIZE; // cell width + spacing 48 + 8
CGFloat y = 0;
CGPoint contentOffset = CGPointMake(x, y);
self.mainCollectionView.contentOffset = contentOffset; */
}
hope its helpful

How to set ScrollView to the initial position programmatically (Swift)

I have 6 buttons on a scroll view and when the user presses on of the buttons all of the buttons change title like a menu. However I would like the ScrollView to reset it self to the top, so the first few buttons are visible and the user is able to scroll down once again.
If you are using a scrollView, simply change scrollView.contentOffset to move your scroll view's visible window. Like x:0, y:0 to the top.
You should read some documents to understand contentOffset, contentSize and so on.
Swift 4
self.scrollView.contentOffset = CGPoint(x:250, y:100)
x and y are the respective width and height from the top left corner of your scrollview.
Apple documentation on contentOffset

Resources