【发布时间】:2012-03-24 11:48:14
【问题描述】:
我是 Objective-C 的新手,我希望创建一个相当简单的 Jigsaw。我目前只是在研究制作一个 4 块拼图作为学习该方法的一种方式。
目前,我在屏幕周围放置了 4 个片段,当它们拖动到屏幕上的特定位置时,会捕捉到该位置。
我的问题是尝试为触摸设置动画。我希望触摸的图像扩大一点,但语法有问题。我查看了 Apple 提供的 MoveMe 示例,但在这种情况下它对我没有帮助。下面是代码。我很感激这方面的任何帮助。谢谢。
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
//location of current touch
CGPoint location = [touch locationInView:self.view];
if ([touch view] == image1) {
image1.center = location;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
image1.transform = CGAffineTransformMakeScale(1.5, 1.5);
[UIView commitAnimations];
} else if ([touch view] == image2) {
image2.center = location;
animateFirstTouch:image2;
} else if ([touch view] == image3) {
image3.center = location;
image3.transform = CGAffineTransformMakeScale(1.5, 1.5);
} else if ([touch view] == image4) {
image4.center = location;
image4.transform = CGAffineTransformMakeScale(1.5, 1.5);
}
}
-(void) animateFirstTouch:(UIView *)image {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
self.view.transform = CGAffineTransformMakeScale(1.5, 1.5);
[UIView commitAnimations];
}
image1 的代码有效,图像放大超过 0.5 秒。
image2 的代码抛出错误:表达式结果未用于 animateFirstTouch:image2。
image3 和 image4 的代码放大了没有动画的图像。
【问题讨论】:
标签: objective-c ios animation drag-and-drop