I have a UIScrollview with horizontal pagination, inside which there are five different view. These are scrolling perfectly as required. And now i also have five buttons on the top of my screen, on button action the scrollview will scroll to the required page(for example if user tap on button 3, the scrollview will scroll to third page). So now I want a small view to work as a selectorView(that is if user scrolling to next page the selector view should move to next button during scroll)just below the five buttons. This is also working fine to some extent but there is small issue specially in iPad devices. The issue is that my selectorView is not finishing in the center of required button. How can it be in the center of required button. I have used below code to move the selectorView.
func scrollViewDidScroll(_ scrollView: UIScrollView) {
let newxPosition = scrollView.contentOffset.x
if UIDevice().userInterfaceIdiom == .phone {
UIView.animate(withDuration: 0.1) { [self] in
self.movingSelectorView.frame.origin.x = newxPosition/5 + (movingViewXConstant ?? 25)
}
} else if UIDevice().userInterfaceIdiom == .pad {
UIView.animate(withDuration: 0.1) { [self] in
self.movingSelectorView.frame.origin.x = newxPosition/5 + (movingViewXConstant ?? 75)
}
}
}
Please see the image uploaded for better understanding. The five buttons are not in the scrollview as well as the movingSelectorView is also not inside the scrollView.

Without getting details from you on your view hierarchy and current code, I'll guess at something that you may find useful.
Let's:
We'll set the initial frame of the selector view to a size of
(20, 3), and position it under the title label of the "Day" buttons.The
center.xvalue of the selector view frame will start at one-half of the width of the first Day button.When the scroll view scrolls - whether being dragged or by calling
.scrollRectToVisibleon a button tap - we'll get the percentage it has scrolled, and update thecenter.xof the selector view to the same percentage of the total buttons width, offset by the "one-half button width" value.So, example code:
and how it looks when running:
This will work - with Zero code changes - independent of device / view size:
Note: This is EXAMPLE CODE ONLY!!! -- it is meant to help you get started, and is not intended to be "Production Ready"