【发布时间】:2010-08-10 11:13:12
【问题描述】:
我正在尝试创建一个挥杆计,有点像高尔夫游戏中使用的挥杆计,用户按住按钮开始挥杆,在顶点释放以确定力量,此时“挥杆”反转方向,并且用户在向下的过程中再次点击以设置精度。
我想使用一个从左到右摆动的钟摆,而不是填满一个条。摆锤在第一次敲击的地方留下一个标记(功率),在第二次敲击的地方留下另一个标记(准确度)。
我的第一个问题是旋转钟摆。我一直在阅读这些关于旋转 UIImageView 的帖子 - here、here 和 here,但我希望我能得到一些额外的建议 :)
首先,旋转 UIImageView 是解决此问题的最佳方法吗?我正在考虑通过将钟摆的坐标与正确点的坐标进行比较来确定钟摆与正确点的距离。但要使其正常工作, UIImageView 必须物理移动,我不确定它是否会移动?此外,如何使 UIImageView 围绕特定点而不是中心点旋转。或者我应该只是让钟摆的边界框更大,这样中心点就在正确的位置。以及如何在用户点击(或释放)按钮的地方留下“印章”?
任何有关解决此问题的最佳方法的一般帮助将不胜感激 :) 也许我的问题有点模糊和笼统,但我希望有人会喜欢这个挑战 :)
谢谢!!
迈克尔
更新:
好的,我尝试了以下两种方法,现在都可以使用。
- (void)viewDidLoad {
pendulum.image = [UIImage imageNamed:@"winkOpen.png"];
[self swingPendulum];
}
- (void)swingPendulum {
CABasicAnimation *rotationAnimation;
rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
rotationAnimation.toValue = [NSNumber numberWithFloat:degreesToRadian(180)];
rotationAnimation.duration = 0.75;
rotationAnimation.repeatCount = 1.0;
rotationAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
[pendulum.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
}
/*
- (void)swingPendulum {
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
pendulum.transform = CGAffineTransformMakeRotation(degreesToRadian(180));
[UIView setAnimationDelegate:self];
[UIView commitAnimations];
}
*/
现在我不确定哪种方法更好,但在第一种方法中,钟摆摆动高于 0 度而不是低于 0 度,所以我会采用这种方法。
现在我需要确定钟摆在哪里停止并反转摆动...但也许我会将这些问题作为单独的问题发布,因为这有点混乱!我会确保我的问题将来更具体:)
【问题讨论】:
-
我认为“Swingometer”,听起来很有趣!然后我读了这个问题,发现它是关于高尔夫的。叹。谈论失望。
-
其实我并没有将它用于高尔夫比赛,我只是认为这是一个最能准确描述问题的例子。这很有趣,我保证:)
-
您看到的那些“未定义符号”错误是因为您没有链接 QuartzCore 框架(其中包含核心动画类和数据类型)。另外,作为一个实际问题,用户在摆动时如何实际看到显示器?
-
但是我已经像这样导入了 QuartzCore 库:#import
那应该可以吗?如果我没有它,我会收到更多来自编译器的投诉......至于看到显示 - 调用函数时不会播放此动画吗?? -
@Smikey - 这只是导入一个标题。您还需要链接框架(这些是您看到的链接器错误)。为此,请右键单击您的项目并转到添加 |现有框架...并从列表中选择 QuartzCore.framework。
标签: iphone objective-c uiimageview rotation cgaffinetransform