如何在拖入 iOS 时修改 UIVisualEffectView 的模糊度?
How can blurriness of UIVisualEffectView be modified while dragging in iOS?
目前,我正在使用 UIVisualEffectView 对图像应用模糊。
我有一个 UIScrollView。当我下拉 scrollView 时,在我的 "scrollViewDidScroll" 方法中,我正在更改 UIVisualEffectView 的 alpha。当前的行为是,当我在视图中四处拖动时,模糊半径会平滑变化。
当然,问题是我不应该这样做。获取有关更改 UIVisualEffectView 的 alpha 值的警告。
我看到有人说要使用动画来平滑过渡模糊,就像这里这样:
但是,我还没有看到任何允许我在此期间执行此操作的东西,比如泛手势之类的。我的意思是,如果我设置一个定时动画,一切都很好。但是在拖动过程中这样做?
有办法:)
正如您所注意到的,您可以从 nil
效果动画到 UIBlurEffectStyleDark
这样的效果,因此如果我们添加动画然后暂停图层的动画,我们可以控制通过调整图层的 timeOffset
!
效果
- (void) setupBlur {
// Setup the blur to start with no effect
self.blurredEffectView = [[UIVisualEffectView alloc] initWithEffect:nil];
// Add animation to desired blur effect
[UIView animateWithDuration:1.0 animations:^{
[self.blurredEffectView setEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleDark]];
}];
// Pause layer animations
self.blurredEffectView.layer.speed = 0;
}
在 0.0 和 1.0 之间调整模糊(动画持续时间):
- (void) adjustBlur:(CGFloat)blurIntensity {
self.blurredEffectView.layer.timeOffset = blurIntensity;
}
- 注意:这不适用于不支持 UIBlurEffect 动画的 iOS8。
目前,我正在使用 UIVisualEffectView 对图像应用模糊。
我有一个 UIScrollView。当我下拉 scrollView 时,在我的 "scrollViewDidScroll" 方法中,我正在更改 UIVisualEffectView 的 alpha。当前的行为是,当我在视图中四处拖动时,模糊半径会平滑变化。
当然,问题是我不应该这样做。获取有关更改 UIVisualEffectView 的 alpha 值的警告。
我看到有人说要使用动画来平滑过渡模糊,就像这里这样:
但是,我还没有看到任何允许我在此期间执行此操作的东西,比如泛手势之类的。我的意思是,如果我设置一个定时动画,一切都很好。但是在拖动过程中这样做?
有办法:)
正如您所注意到的,您可以从 nil
效果动画到 UIBlurEffectStyleDark
这样的效果,因此如果我们添加动画然后暂停图层的动画,我们可以控制通过调整图层的 timeOffset
!
- (void) setupBlur {
// Setup the blur to start with no effect
self.blurredEffectView = [[UIVisualEffectView alloc] initWithEffect:nil];
// Add animation to desired blur effect
[UIView animateWithDuration:1.0 animations:^{
[self.blurredEffectView setEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleDark]];
}];
// Pause layer animations
self.blurredEffectView.layer.speed = 0;
}
在 0.0 和 1.0 之间调整模糊(动画持续时间):
- (void) adjustBlur:(CGFloat)blurIntensity {
self.blurredEffectView.layer.timeOffset = blurIntensity;
}
- 注意:这不适用于不支持 UIBlurEffect 动画的 iOS8。