问题标签 [uiviewpropertyanimator]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
101 浏览

swift - 在 Swift 中向 UIViewPropertyAnimator 添加完成处理程序

我试图让属性动画师在呈现视图控制器时启动动画。现在动画正在播放,但是UIViewPropertyAnimator不响应添加到它的完成处理程序。

  • UIVisualEffectView子类。
  • 第一个视图控制器
  • 第二个视图控制器

这里UIViewPropertyAnimator完成处理程序是在第二个视图控制器(具有视觉效果视图的控制器)出现之后添加的。我曾尝试将完成处理程序移动到不同的地方viewDidLoadviewDidAppear但似乎没有任何效果。

0 投票
1 回答
187 浏览

ios - Manually scrolling UIScrollView which is animated by UIViewPropertyAnimator

I have a UIScrollView which scrolls automatically by setting its content offset within via a UIViewPropertyAnimator. The auto-scrolling is working as expected, however I also want to be able to interrupt the animation to scroll manually.

This seems to be one of the selling points of UIViewPropertyAnimator:

...dynamically modify your animations before they finish

However it doesn't seem to play nicely with scroll views (unless I'm doing something wrong here).

For the most part, it is working. When I scroll during animation, it pauses, then resumes once deceleration has ended. However, as I scroll towards the bottom, it rubber bands as if it is already at the end of the content (even if it is nowhere near). This is not an issue while scrolling towards the top.

Having noticed this, I checked the value of scrollView.contentOffset and it seems that it is stuck at the maximum value + the rubber banding offset. I found this question/answer which seems to be indicate this could be a bug with UIViewPropertyAnimator.

My code is as follows:

Is there anywhere obvious I'm going wrong here? Or any workarounds I can employ to make the scroll view stop rubber banding on scroll downwards?

0 投票
1 回答
48 浏览

swift - 使用 UIVIewPropertyAnimator 摇动视图

我正在尝试使用完成处理程序编写抖动功能。当我调用函数时,我可以看到抖动本身,但它的幅度远小于期望值。请查看代码并帮助我修复错误。

0 投票
1 回答
46 浏览

ios - 中断和反转 CAKeyframeAnimation

我有一个可以选中或取消选中的复选框视图。我想为复选标记的绘图设置动画,为此,我使用 CAKeyframeAnimation 并在 CAShapeLayer 上绘图。

这很好用,但我也希望能够支持在抽签中撤销检查决定。现在动画的持续时间被配置为一秒。因此,如果一个人点击视图并且复选标记开始绘制但随后在 0.5 秒的时间点击视图,那么我希望动画停止绘制并开始反转。同样,如果未选中复选标记并且该人点击它,那么我希望它反转其清除动画并再次开始绘制复选标记。

我只是不知道该怎么做。我不知道 CAKeyframeAnimation 是否可以实现,或者我是否应该使用 UIViewPropertyAnimator 或其他东西,或者我什至可以使用 UIViewPropertyAnimator,因为它是一个视图动画器,我正在为 CAShapeLayer 上的属性设置动画。而且我将复选标记分为三部分(一个起始点,复选标记的第一个向下部分和整个复选标记),所以我不知道如何使用 UIViewPropertyAnimator 对其进行动画处理(也许链接动画,但是那么这似乎会使反转动画变得困难)。

这是我的代码。有没有人对如何使这种可中断和可逆的有任何想法?

MyCheckmarkView.h

MyCheckmarkView.m

更新

这是我根据@DonMag 的代码更新的动画部分代码。一切正常,除了动画开始时,似乎直接将图层的strokeEnd值设置为所需的结束值,然后开始动画。这可能是因为我在方法的最后设置了 strokeEnd 属性,但这样在动画被删除并且presentationLayer 更新为原始内容层属性中的值后,该值将保持不变。

我也尝试过使用 CATransaction,然后在 completionBlock 中设置它,但这只会产生相反的效果。动画开始并成功完成,但随后动画被删除并短暂显示旧状态,然后(出于某种原因)快速动画,即使我没有做任何明确的动画动画(我猜这可能是一个隐式动画财产?)。

但我认为无论如何我都不应该使用 CATransaction,因为我将动画添加到图层,然后在表示层显示动画时更新属性。这是不正确的,有没有更好的方法来做到这一点?如果可能的话,我希望动画能够被移除,并且在动画被移除后原始层显示正确的状态。

这是我检查和未检查状态的代码。

动画到选中状态

动画到未选中状态

0 投票
0 回答
18 浏览

swift - 使用带有重复和自动反转选项的 UIViewPropertyAnimator

我在这里检查了所有现有的类似问题,但找不到解决方案。

我正在尝试执行以下属性动画,该动画应该自动反转并重复直到事件发生,然后我将停止它:

编译器会忽略.autoreverseand.repeat选项,并且只执行一次动画。

不过,对我有用的是在动画闭包中添加以下两行:

然而,Xcode 不喜欢这样,并提出两个警告:

'setAnimationRepeatCount' 在 iOS 13.0 中已弃用:改用基于块的动画 API 'setAnimationRepeatAutoreverses' 在 iOS 13.0 中已弃用:改用基于块的动画 API

是否有任何可能的方法来自动反转和重复属性动画而不必使用已弃用的代码?

请不要建议使用UIView.animate(..)代替UIViewPropertyAnimator