我是 iOS 图形和动画的新手,想知道如何实现图像在轻弹时的动量旋转效果,如下面的视频所示。
http://www.youtube.com/watch?v=ZIQs-OWgkgI
(现在坏了)
即使没有轻弹,图像也有很好的摇摆感。
谢谢。
这很漂亮。它围绕一个点(顶部的中心)旋转视图,然后通过算法更改旋转所需的时间量,并在适当时反转。我不能给你代码,但我认为如果你观看 Hegarty 教授的这个视频演示,你就会拥有你需要的工具。他围绕视图外的一个点旋转 - 您可以简单地围绕视图边缘旋转(并且不要缩小视图)。一探究竟:
第 1 部分:http: //www.stanford.edu/class/cs193p/cgi-bin/drupal/node/291
第 2 部分:http: //www.stanford.edu/class/cs193p/cgi-bin/drupal/node/293
您肯定想从 iTunes U(免费)下载视频,因为有很多解释。
祝你好运,
达米安
//this code can be used to rotate an image having both back and front
rotate = [UIButton buttonWithType:UIButtonTypeCustom];
[rotate addTarget:self action:@selector(rotate1)forControlEvents:UIControlEventTouchDown];
rotate.frame = CGRectMake(137.5, 245, 45, 46);
[rotate setBackgroundImage:[UIImage imageNamed:[NSString stringWithFormat:@"viewing.png"]] forState:UIControlStateNormal];
[self.view addSubview:rotate];
int count;
count=0;
-(void)rotate1
{
count=count+1;
NSLog(@"rotate");
[UIView transitionWithView:imagecircle // use the forView: argument
duration:1 // use the setAnimationDuration: argument
options:UIViewAnimationOptionTransitionFlipFromLeft
// check UIViewAnimationOptions for what options you can use
animations:^{ // put the animation block here
imagecircle.image = imagecircle.image;
}
completion:NULL];
if(count%2==0)
{
NSLog(@"image.str.%@",appDelegate.imageNameString);
[imagecircle setImage:[UIImage imageNamed:appDelegate.imageNameString]];
[labellocation removeFromSuperview];
[labeldate removeFromSuperview];
[self.imagecircle addSubview:labelfrom];
}
else
{
[imagecircle setImage:[UIImage imageNamed:@"TGP_BACK.png"]];
[labelfrom removeFromSuperview];
[self.imagecircle addSubview:labellocation];
[self.imagecircle addSubview:labeldate];
}
}
我与作者核实过,并被告知它是使用 Box2D 物理库实现的。我要试一试。感谢您的回复!