Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to set selectedSegmentIndex with animation? #17

Open
LhiKien opened this issue Mar 5, 2017 · 4 comments
Open

How to set selectedSegmentIndex with animation? #17

LhiKien opened this issue Mar 5, 2017 · 4 comments
Projects

Comments

@LhiKien
Copy link

LhiKien commented Mar 5, 2017

Can you tell me how to set the "selectedSegmentIndex" with animation from another UI control or data source? Not just change the value of LUNSegmentedControl by clicking it.

@LhiKien
Copy link
Author

LhiKien commented Mar 5, 2017

[self.segmentedControl setCurrentState:2];

This code will change the state with no animation.
How to add animation to this operation?

@pavolkmet
Copy link

pavolkmet commented Jan 25, 2018

@LhiKien Try to use this code it should work.

- (void)setSegmentedControlIndex:(NSUInteger)index animated:(BOOL)animated
{
    [UIView animateWithDuration:animated ? 0.3 : 0.0 delay:0.0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
        [self.segmentedControl setCurrentState:index];
    } completion:nil];
}

@AnthoPakPak
Copy link

AnthoPakPak commented Apr 5, 2018

@pavolkmet Just tested your code and it doesn't work.

Just expose the method
- (void)setCurrentState:(NSInteger)currentState animated:(BOOL)animated;

in LUNSegmentedControl.h and use it and it will work 👍

@seland
Copy link
Collaborator

seland commented Mar 28, 2020

I think it's not possible with current implementation, but would be a good improvement to expose animated setter as well. Noted.

@seland seland added this to To do in 2.0 Mar 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
2.0
  
To do
Development

No branches or pull requests

4 participants