gpt4 book ai didi

ios - MPVolumeView 动画问题

转载 作者:可可西里 更新时间:2023-11-01 04:23:20 27 4
gpt4 key购买 nike

每次我将 MPVolumeView 作为我的 UIViewController View 的 subview 添加时,都会有一个快速动画(MPVolumeView 从左侧展开向右)看起来真的很奇怪。我正在寻找摆脱此动画的方法,有人遇到过这个问题吗?

我几乎承认这是一个 MPVolumeView 错误,但后来我注意到 Apple 肯定在他们的原生音乐应用程序中使用了 MPVolumeView,那里没有奇怪的动画......所以一定是我做错了什么。

更新:

代码非常简单,但在评论中要求,所以这里是:

MPVolumeView *volumeView = [[MPVolumeView alloc] initWithFrame:CGRectMake(10.f, 0.f, CGRectGetWidth(self.view.frame) - 20.f, 30.f)];
[[UISlider appearanceWhenContainedIn:[MPVolumeView class], nil] setMinimumValueImage:[UIImage imageNamed:@"icon-volumeMin"]];
[[UISlider appearanceWhenContainedIn:[MPVolumeView class], nil] setMaximumValueImage:[UIImage imageNamed:@"icon-volumeMax"]];
volumeView.center = CGPointMake(0.5f * CGRectGetWidth(self.view.frame), 0.5f * CGRectGetHeight(self.view.frame));
volumeView.showsRouteButton = NO;
[self.view addSubview:volumeView];

我做了一个很简单的project在 github 上演示问题,但您必须在设备上运行它,因为 MPVolumeView 不会显示在模拟器上。或者看看这个 gif:

gif :

最佳答案

消除此行为的一种可能方法是继承 MPVolumeView 并在 [super layoutSubviews] 之后执行一些额外的工作。

- (void)layoutSubviews
{
[super layoutSubviews];

[self xy_recursiveRemoveAnimationsOnView:self];
}

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

这将删除所有插入的动画。因此,请确保这就是您想要的,因为这太过分了。也可以只删除 positionbounds 动画(参见 removeAnimationForKey:)。

关于ios - MPVolumeView 动画问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27878272/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com