ios - 为什么 "+ (void)setAnimationStartDate:(NSDate *)startDate;"不起作用

标签 ios objective-c nsdate uiviewanimation

我正在研究UIView Animation,我在使用“+ (void)setAnimationStartDate:(NSDate *)startDate;”时发现在 beginAnimations:context:commitAnimations 方法之间,它不起作用

[UIView beginAnimations:@"demo" context:nil];
[UIView setAnimationDuration:3.0f];
[UIView setAnimationStartDate:[NSDate date]];
// do something
[UIView commitAnimations];

因为方法默认是现在(NSDate 日期),我什至尝试“[NSDate dateWithTimeIntervalSinceNow:5]”,它也不起作用。

如果我不使用该方法,它会像往常一样工作。谢谢。

最佳答案

您正在调用 setAnimationStartDate,这意味着您正在为此动画提供开始时间。所以,在那个时候到来之前,它不会开始。

作为Apple Documentation州,

Call this method between the beginAnimations:context: and commitAnimations methods to specify the start time for that set of animations. And call this method prior to changing the animatable properties of your views. (Do not call this method in conjunction with a block-based animation.) If you do not call this method, the start time is set to the value returned by the CFAbsoluteTimeGetCurrent function, which begins the animations as soon as possible.

在 iOS 4.0 及更高版本中不鼓励使用此方法。您应该使用基于 block 的动画方法来指定您的动画。

有关详细信息,请参阅文档。

希望这会有所帮助:)

关于ios - 为什么 "+ (void)setAnimationStartDate:(NSDate *)startDate;"不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37321368/

相关文章:

ios - 如何在多个 tableViewController 时推送 ViewController(无 Storyboard)

ios - 图片.xcassets : How to use one image for all resolutions

ios - 如何使 autosize(height) UITableViewCell?

objective-c - 如何创建 size_t 以及如何计算大小?

iOS - 表格 View 渲染

ios - 为什么文字是颠倒的?

ios - Xcode下架构x86_64的重复符号

ios - NSDate - dateFromString 返回 nil

objective-c - 将当前日期添加到日期选择器 objective-C 的前一天和后一天

ios - 两个日期之间的时间差导致错误或未知值