0

The UISegmentedControl is placed in the UINavigationBar and has two elements (e.g @"One" and @"Two"). The UIViewController contains a UIScrollView with two pages with horizontal scrolling. The segmented control indicates wich of the pages is currently displayed. I know how this works, but I want to implement it so while scrolling the selected tab changes smoothly. Just like in the Apple Music app...

nburk
  • 22,409
  • 18
  • 87
  • 132
  • What have you tried? Where are you stuck at? Or are you just asking how to do be whole thing? – soulshined Jul 12 '15 at 14:37
  • The Apple Music app does not "change the selected tab smoothly". It just changes, kaboom. – matt Jul 12 '15 at 15:24
  • @matt No, it does change it "smoothly"! I uploaded a short clip of what i mean: https://drive.google.com/file/d/0B6LzUF2e3z2rZUVoOVRNeTBNSWs/view?usp=sharing – MothaFvckaJones Jul 12 '15 at 15:42
  • My Music app doesn't look like that at all. What iOS version is that in your movie? – matt Jul 12 '15 at 15:47
  • @matt I am using iOS 9 beta 3, But it should be the same in iOS 8.4 final – MothaFvckaJones Jul 12 '15 at 15:48
  • I am using iOS 8.4 final (much to my regret) and it doesn't look like that at all... – matt Jul 12 '15 at 15:53
  • okay, so this is only a iOS 9 thing i guess... But since i have never seen this before i was wondering how this is implemented. I don't know how to get the segmentedControl in this "superposition" where no Index is actually selected but both are painted according to the percentage how much of each side is visible (i guess ?) – MothaFvckaJones Jul 12 '15 at 15:57
  • Looks like one of those zero-speed `timeOffset`-based interactive animations. – matt Jul 12 '15 at 16:12

1 Answers1

3

So it turns out that setting the selected index of a segmented control is now animatable:

UIView.animateWithDuration(4) {
    self.seg.selectedSegmentIndex = 1
}

So they must be doing that, coordinating it with the interactive scrolling of the view by setting the layer speed to 0 and changing the timeOffset, as I explain here: https://stackoverflow.com/a/22677298/341994

Community
  • 1
  • 1
matt
  • 515,959
  • 87
  • 875
  • 1,141