gpt4 book ai didi

iPhone SDK : Block Animation Ignore Error with Curved Path

转载 作者:行者123 更新时间:2023-11-28 17:43:46 25 4
gpt4 key购买 nike

我正在创建一个应用程序,用户可以在屏幕上从一个对象到他们想要发送它的位置画一条线,然后该对象将沿着这条线到达最终位置。为了做到这一点,我已经创建了工作方法来允许用户绘制线条,然后将线条的坐标存储在 MutableArray 中。但是,当我尝试制作动画时遇到了一些麻烦。由于我是 iPhone 操作系统的新手,这可能是一个简单的问题,但我还没有找到解决方案。

我没有使用贝塞尔路径,因为用户手动绘制线条,我没有以编程方式绘制。

这是我试过的代码

-(void)animateButtonWasPressed
{
for (int f = 0; f < [cordArrayY count]; f++) {
NSString *newY = [cordArrayY objectAtIndex:f];
NSString *newX = [cordArray objectAtIndex:f];

[self myAnimate:newX :newY];
}
}

-(void)myAnimate:(NSString *)PntX :(NSString *)PntY
{
[UIView animateWithDuration:.5 animations:
^{
object.center = CGPointMake([PntX floatValue], [PntY floatValue]);
}];

}

语法:object - 我要移动的对象cordArray - 包含 x 坐标的可变数组cordArrayY - 包含 y 坐标的可变数组

其他所有内容要么在代码中定义,要么在 Apple 方法中定义

问题:对象立即从其原始位置直接移动到最终位置。我得到一个 NSLog,它告诉我这个:

-[UIApplication endIgnoringInteractionEvents] called without matching -beginIgnoringInteractionEvents. Ignoring.

如有任何帮助,我们将不胜感激!

最佳答案

您用来为“对象”设置动画的方法似乎没问题。我相信问题出在您调用该方法的循环中。您正试图在该循环的每个步骤中一遍又一遍地为对象的相同属性设置动画。我认为这会导致“跳跃”。

看看 Apple 文档中的这段引述:

Important: Changing the value of a property while an animation involving that property is already in progress does not stop the current animation. Instead, the current animation continues and animates to the new value you just assigned to the property.

http://developer.apple.com/library/ios/#documentation/WindowsViews/Conceptual/ViewPG_iPhoneOS/AnimatingViews/AnimatingViews.html#//apple_ref/doc/uid/TP40009503-CH6

作为在每个步骤中调用动画的结果,您将在大约 0.5 秒内将对象动画化到坐标数组的最后位置。

我认为您应该将这些动画链接在一起,但您应该等待每个动画完成后再开始下一个动画。看看这个

Another thing that both the animateWithDuration:animations:completion: and animateWithDuration:delay:options:animations:completion: methods support is the ability to specify a completion handler block. You might use a completion handler to signal your application that a specific animation has finished. Completion handlers are also the way to link separate animations together.

希望对您有所帮助,

干杯。

关于iPhone SDK : Block Animation Ignore Error with Curved Path,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7031597/

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