Herbert77 / HHSlideView

A custom segment control view with flat style.
MIT License
53 stars 9 forks source link

Bug when rotate the app #4

Open CavalcanteLeo opened 7 years ago

CavalcanteLeo commented 7 years ago

There is a bug when you rotate the app from portrait to landscape, i've fixed it, but didn't send a PR.

adding this code should fix a little it:

- (instancetype)initWithFrame:(CGRect)aFrame {
    self = [super initWithFrame:aFrame];
    if (self) {
        [self initData];
        [self listenOrientationChanges]; //added a notification 
    }
    return self;
}

//also included init with coder, in case someone wants to use with storyboard
-(instancetype)initWithCoder:(NSCoder *)aDecoder{
    if ((self = [super initWithCoder:aDecoder])) {
        [self initData];
        [self listenOrientationChanges]; //added a notification 
    }
    return self;
}

-(void)listenOrientationChanges{
    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:[UIDevice currentDevice]];
}

- (void)orientationChanged:(NSNotification *)note{
    [self resetViews];
}

-(void)resetViews{
    [[self.slideBar subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)];

    [self addSlideBar];
    [self addButtons];
    [self addSlider];
    // Here still a bug with the slideBar bottom line
}
Herbert77 commented 7 years ago

Man, I'm very grateful to you for this amendment. I'll change it as soon as possible to make it better.😊

CavalcanteLeo commented 7 years ago

I'm really busy atm, otherwise i could send this PR, but if need any help, i will arrange a time to help u.

Herbert77 commented 7 years ago

Thanks a lot. If I have a tough problem, I'll consider asking for your help. Recently, I have some company projects on hand, and I will use my spare time to fix it.🙂

CavalcanteLeo commented 7 years ago

k, im here to help

hemangshah commented 7 years ago

@Herbert77, hey, Is this fixed? Cheers for the good work! 👍

Herbert77 commented 7 years ago

Hello, I have refactoring the framework. Using Masonry for Autolayout, support horizontal screen mode. Thanks for your support.