MPVolumeView animation on iOS 8

旧巷老猫 提交于 2019-12-21 04:11:34

问题


In iOS 8 there is a problem or a feature. When MPVolumeView is shown, it's being animated, like expanding from 0 to it's width. How can I fix that behavior? There was no such problem on iOS 7.


回答1:


One possible way to remove this behavior is to subclass MPVolumeView and perform some additional work after [super layoutSubviews].

- (void)layoutSubviews
{
    [super layoutSubviews];

    [self cg_recursiveRemoveAnimationsOnView:self];
}

- (void)cg_recursiveRemoveAnimationsOnView:(UIView *)view
{
    [view.layer removeAllAnimations];
    for (UIView *subview in view.subviews) {
        [self cg_recursiveRemoveAnimationsOnView:subview];
    }
}

This removes all inserted animations. So be sure that is what you want, since this is quite the overkill. One could also just remove the position and bounds animations (see removeAnimationForKey:).




回答2:


I confirm that this problem still exists in iOS 8. The workaround provided by Anastasia in one of the comments above (with overriding volumeSliderRectForBounds) seems to work but only when route button is not present. When it is present the slider overlaps the route button and it can no longer be pressed.

I made a simple modification of her solution, maybe someone can use it as a workaround, until Apple fixes that or better solution is provided.

- (CGRect)volumeSliderRectForBounds:(CGRect)bounds
{
    if (self.showsRouteButton) {
        NSInteger spacer = 10; /* Space between Route button and Volume slider */
        CGRect routeButtonRect = [self routeButtonRectForBounds:bounds];
        bounds.size.width -= (routeButtonRect.size.width + spacer);
    }
    return bounds;
}

I don't like hardcoding the spacer value, but I could not find how to calculate it dynamically.



来源:https://stackoverflow.com/questions/25868915/mpvolumeview-animation-on-ios-8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!