Creation of a Horizontal Infinite Scrolling Menu Bar in iOS
Your request is very similar to mine. But I cannot find a good enough solution too. So I decide to create something to do that by myself.
The ACTabScrollView supports some different gestures. And the tabs
and pages
will always scroll synchronously.
Swipe
pages normallyDrag
tabs can quickly move pagesClick
a tab to change to that page
The Infinite Scrolling
feature is not ready yet, but I will keep to implement.
I use the similar UI as examples in this project. I don't know what the app is, but if using it as an example bother anyone. Contact me and I will immediately remove that.
Feel free to give me any suggestion to improve it :)
I hope this code will work for you.
- (void)viewDidLoad{ [super viewDidLoad]; [self createHorizontalScroll];}- (void)createHorizontalScroll{ UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 80, self.view.frame.size.width, 80)]; int buttonX = 0; for (int i = 0; i < 5; i++) { UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(buttonX, 0, 100, 60)]; [button setTitle:[NSString stringWithFormat:@"Button %d", i] forState:UIControlStateNormal]; [scrollView addSubview:button]; buttonX = buttonX+button.frame.size.width; [button addTarget:self action:@selector(changeView:) forControlEvents:UIControlEventTouchUpInside]; }scrollView.contentSize = CGSizeMake(buttonX, scrollView.frame.size.height);scrollView.backgroundColor = [UIColor greenColor];[self.view addSubview:scrollView];} -(void)changeView:(UIButton*)sender { NSLog(@"I Clicked a button %ld",(long)sender.tag); }
You can set scroll content as much you want and menu buttons.Change the view according to the button click. Here the screen shot of the above code
I hope this might help you. This doesn't have more animation but works as you expected.
You can make use of CollectionView in this to scroll Horizontally with menu options as CollectionView Cell. For achieving the left and right swiping we can use UISwapeGuestureRecognizers and can scroll between pages.
Here is how i have implemented it using CollectionView for ScrollableMenu as tabs in the top of the screen and the Pages in the bottom of the menu using Container View.
You can download this project and check for getting idea about the implementation form the below link.
Hope this might help you. This is implemented with lates Swift 4.0 and X-Code 9.2
Happy Coding..