Mohammed Hussain Mohammed Hussain - 5 months ago 18
iOS Question

How To Scroll the line between the buttons

I want to scroll the line (uiview - Hieght=1) between the button And i had put the button in container view of pageviewcontroller.Pageviewcontroller is starting from bottom of the buttons .I want the line to move when i scroll pageviewcontrollers subviews.
The Image as shown below...
enter image description here

So this line white line I want to move when I scroll page 1 to 2 then 2 - 1 How can i do this Please help....
As I have to use pageviewcontroller

Answer

you can do this in with help of UIScrollView , in here no need of UIpageViewController

take the delegate methods of

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView;
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate;
- (void)scrollViewDidScroll:(UIScrollView *)sender;

Step-1

create the one scrollView like self.tblScroll

//It call end of scroll

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
if (scrollView != MovemylineinBlack && scrollView != MovemylineinRed)
{
    int x=fmod(scrollView.contentOffset.x, self.tblScroll.frame.size.width);
    if (x <= self.tblScroll.frame.size.width/2 )
    {
        [scrollView setContentOffset:CGPointMake(scrollView.contentOffset.x-x, scrollView.contentOffset.y) animated:YES];
    }
    else
    {
        [scrollView setContentOffset:CGPointMake(scrollView.contentOffset.x+self.tblScroll.frame.size.width-x, scrollView.contentOffset.y) animated:YES];
    }
   }
}

Step-2

// it s call your scroll is closusre

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate: (BOOL)decelerate
{
if (scrollView != MovemylineinBlack && scrollView != MovemylineinRed)
{
    int x=fmod(scrollView.contentOffset.x, self.tblScroll.frame.size.width);
    if (x <= self.tblScroll.frame.size.width/2 )
    {
        [scrollView setContentOffset:CGPointMake(scrollView.contentOffset.x-x, scrollView.contentOffset.y) animated:YES];
    }
    else
    {
        [scrollView setContentOffset:CGPointMake(scrollView.contentOffset.x+self.tblScroll.frame.size.width-x, scrollView.contentOffset.y) animated:YES];
    }
   }
 }

Step-3

// Imeplement the every drag of move capture method

- (void)scrollViewDidScroll:(UIScrollView *)sender
{
  if (self.tblScroll.contentOffset.x<KAPPDeviceWidth/2) // KAPPDeviceWidth--> this is your view Width
{
    self.viewSubBack.frame=CGRectMake(self.tblScroll.contentOffset.x, 106, 160, 5); // viewSubBack --> is your white line
}
else
{
    self.viewSubBack.frame=CGRectMake((KAPPDeviceWidth/2)+1, 106, 160, 5);
}
}