对于具有通常的四个点a,b,c和d的三次Bézier曲线,
对于给定值t,
如何最优雅地找到那一点的切线?
对于完全适合动画组方法的动画效果,如Brad Larson的答案所示,我需要动画根据输入继续进行.具体地说是检测到的触摸的触摸和位置.它很容易处理touchesMoved:并为每次触摸设置元素的位置,但它不像核心动画方法那样平滑.
想象一下在沟槽轨道上的大理石.我想把大理石沿着一个方向或另一个方向以任何速度推到任何位置.动画必须做类似的事情,沿着路径移动视觉元素以响应触摸.CAKeyframeAnimation具有完全相同的路径位,但似乎总是希望基于时间过去的帧到帧的过渡,而不是基于任何其他因素,并且在一个方向上.
1月31日更新 - 感谢所有回复到目前为止,但没有一个真正解决问题.我有一个圆形菜单被拖动以选择一个选项.所有这些都需要一起移动,我通过使用一个应用了旋转变换的视图并将逆旋转变换应用于其子视图来解决它,因此图标都以适当的摩天轮方向旋转.当图标沿着略微卵形的路径动画时,它看起来确实更好......大理石描述试图弄清楚我正在尝试做什么.更好的想法可能是想象磁铁可以排斥所有在凹槽中移动的东西 - 移动一个并且它的邻居也可以移动但不一定在拖动的磁铁随着路径弯曲的方向移动.
现在问题是跟随用一个圆创建的简单路径之一,但我真的想知道如何沿任意路径动画对象,仅通过触摸控制位置而不涉及速度或方向的计算.
如何沿特定的UiBezierPath移动球?那可能吗?
我已经尝试了一切,包括使用命中测试
-(BOOL)containsPoint:(CGPoint)point onPath:(UIBezierPath*)path inFillArea:(BOOL)inFill
Run Code Online (Sandbox Code Playgroud)
如何检测路径上的触摸?
我正在开发一款带有一些简单动画的iPhone应用程序.
我有一个想要翻译的观点,但不是一条线.我想抛物面翻译它.想象一下,我正在制作一辆沿弯曲道路行驶的汽车.
我知道我可以将转换正确地设置为CGAffineTransform的实例
问题是,我不知道如何创建转换.我知道如何缩放,翻译等,但我如何翻译?它甚至可能吗?
这可能吗?我可以更改图层的不透明度和位置(中心),但每当我尝试更改大小或原点时,它都不起作用.
CAAnimationGroup* anigroup = [CAAnimationGroup new];
CGMutablePathRef thePath = CGPathCreateMutable();
CGPathAddRect(thePath, NULL, CGRectMake(0,0, 320, 480));
CGPathAddRect(thePath, NULL, CGRectMake(location.x - 16,location.y-24, 32, 48));
CGPathAddRect(thePath, NULL, CGRectMake(190, 20, 32, 48));
CAKeyframeAnimation* AniLoc = [CAKeyframeAnimation animationWithKeyPath:@"frame"];
AniLoc.path = thePath;
AniLoc.keyTimes= [NSArray arrayWithObjects:[NSNumber numberWithFloat:0.0f],
[NSNumber numberWithFloat:0.3f],
[NSNumber numberWithFloat:1.0f],nil];
AniLoc.duration = 5;
CFRelease(thePath);
anigroup.animations = [NSArray arrayWithObjects:AniLoc,nil];
anigroup.duration = 5;
[focusview.layer addAnimation:anigroup forKey:nil];
Run Code Online (Sandbox Code Playgroud) 我正在开发一种UIImageView沿着Bezier路径移动的游戏.我想为移动提供用户交互,UIimageview以便用户可以UIImageView通过触摸UIImageView并在路径上拖动来引导它!怎么做到这一点?

我想用bezier路径移动更改rect:
CAShapeLayer *shapeLayer = [CAShapeLayer layer];
shapeLayer.path = [self createArcPath].CGPath;
shapeLayer.strokeColor = [[UIColor blueColor] CGColor];
shapeLayer.lineWidth = 1.0;
shapeLayer.fillColor = [[UIColor clearColor] CGColor];
[self.view.layer addSublayer:shapeLayer];
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
// btn.frame = CGRectMake(326, 174, 64, 64);
[btn setBackgroundImage:[UIImage imageNamed:@"Volleyball_Ball.png" forState:UIControlStateNormal];
[self.view addSubview:btn];
// car = [CALayer layer];
// car.frame = CGRectMake(326, 174, 48, 48);
// car.contents = (id)([UIImage imageNamed:@"1453303583_circle_blue.png"].CGImage);
// [self.view.layer addSublayer:car];
CAKeyframeAnimation *anim = [CAKeyframeAnimation animationWithKeyPath:@"position"];
anim.path = [self createArcPath].CGPath;
anim.rotationMode = kCAAnimationRotateAuto;
anim.delegate = self;
anim.repeatCount = …Run Code Online (Sandbox Code Playgroud) 我有一个层将在UIBezierPath上从A点移动到B点.我发现很多样本都是指CAAnimation和UIBezierPath.但是我需要在bezier路径上将我的图层从指定点移动到另一个点.

任何建议,将不胜感激.
谢谢
对于动画计时算法,我需要提供一条路径作为曲线。两端都有控制点的贝塞尔曲线。
问题在于,由于CGPathRef是不透明的,因此似乎无法在CGPath上计算点。苹果也没有提供任何机制来计算路径上的点。
是否有一个库或实用程序类可以针对给定位置(例如沿路径中间的0.5)计算贝塞尔曲线或路径上的点?
还是让我改一下一下:如果CGPath / CGPathRef因为它是不透明的而使此操作不可能,并且如果您只关心贝塞尔曲线,是否有办法计算路径上的位置点?
出于某种原因,Xcode告诉我,只要我使用像kCAFillModeForwards这样的东西就找不到符号.必须有一个图书馆或班级,我必须包括......但是哪一个?正常的核心动画的东西工作得很好[myView beginAnimations ...].让更复杂的动画制作工作的诀窍是什么?
我已经包含在.h文件中:
#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
@interface TestClass : UIView {
}
// ...
Run Code Online (Sandbox Code Playgroud)
我运行这段代码:
- (void)testAnimation {
CABasicAnimation *fadeInAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];
[fadeInAnimation setToValue:[NSNumber numberWithFloat:1.0]];
fadeInAnimation.fillMode = kCAFillModeForwards;
fadeInAnimation.removedOnCompletion = NO;
// other stuff deleted to limit error possibilities...should at least compile
}
Run Code Online (Sandbox Code Playgroud)
这种情况发生在我构建时(确实清理了很多次),2个错误:
cd "/Users/thanks/Desktop/Thanks/iPhone Development/TestApp"
setenv MACOSX_DEPLOYMENT_TARGET 10.5
setenv PATH "/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc-4.0 -arch i386 -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator2.2.1.sdk "-L/Users/thanks/Desktop/Thanks/iPhone Development/TestApp/build/Debug-iphonesimulator" "-F/Users/thanks/Desktop/Thanks/iPhone Development/TestApp/build/Debug-iphonesimulator" -filelist "/Users/thanks/Desktop/Thanks/iPhone Development/TestApp/build/TestApp.build/Debug-iphonesimulator/TestApp.build/Objects-normal/i386/TestApp.LinkFileList" -mmacosx-version-min=10.5 -framework Foundation -framework UIKit -framework CoreGraphics -o "/Users/thanks/Desktop/Thanks/iPhone Development/TestApp/build/Debug-iphonesimulator/TestApp.app/TestApp"
Undefined symbols: …Run Code Online (Sandbox Code Playgroud) 可能重复:
如何沿曲线路径设置视图或图像的移动动画?
我有一个iOS应用程序,我想动画落叶(或几个).我有我的叶子图像,ImageView我从文档中找到了一个简单的动画:
[UIView animateWithDuration:4.0f
delay:0
options:UIViewAnimationTransitionFlipFromLeft
animations:^(void)
{
leaf1ImageView.frame = CGRectMake(320, 480, leaf1ImageView.frame.size.width,leaf1ImageView.frame.size.height);
}
completion:NULL];
Run Code Online (Sandbox Code Playgroud)
这将使叶片从其起始位置直线进入右下角.我如何设置动画来跟随路径或曲线如抛物线或正弦曲线,甚至可能旋转图像或视图?这会在动画块中完成吗?提前致谢!
iphone ×7
ios ×6
cocoa-touch ×5
animation ×3
objective-c ×2
uiview ×2
bezier ×1
c ×1
calayer ×1
cocoa ×1
math ×1
quartz-core ×1
sprite-kit ×1
swift ×1
uiimageview ×1
uikit ×1