UISegmentedControl in iOS 7 divider image is wrong during animation

前端 未结 6 858
清歌不尽
清歌不尽 2020-12-25 15:05

I have a custom UISegmentedControl. In iOS 6 and bellow it works fine. Under iOS 7.. it looks fine until I press the control, at which time, the divider image looks weird fo

6条回答
  •  暖寄归人
    2020-12-25 15:24

    I solved this in a way similar to what user2128193 describes, but instead of adding a target for the value changed event, I subclassed UISegmentedControl and added these two methods:

    - (void)sendActionsForControlEvents:(UIControlEvents)controlEvents
    {
        [super sendActionsForControlEvents:controlEvents];
    
        if (controlEvents & UIControlEventValueChanged) {
            [self removeAnimationsRecursivelyForView:self];
        }
    }
    
    - (void)removeAnimationsRecursivelyForView:(UIView *)view
    {
        [view.layer removeAllAnimations];
    
        for (UIView *subview in [view subviews]) {
            [self removeAnimationsRecursivelyForView:subview];
        }
    }
    

    Obviously this is still not a perfect solution, in that it relies on the internals of UISegmentedControl, but at least it will keep your code a bit cleaner.

提交回复
热议问题