0

我想在按下按钮(360度)后围绕他的中心顺时针旋转一个UIImageView......它应该是一个动画......所以它得到了一个方向盘,它应该自己旋转对用户可见......

我看到有很多方法可以做到这一点,但没有什么对我有用...... :-)

CABasicAnimation,我必须为此添加一个框架吗?

有人可以给我一个示例代码,用于将 UIImageView 围绕其中心旋转(360 度)有效吗?!?

先感谢您

4

3 回答 3

1

听到下面给出的我做同样的事情......但我的要求是当touchBegin时,视图将旋转360度......它可能对你有帮助......

 - (void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {

    self.userInteractionEnabled=YES;
[UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.5];
[UIView setAnimationBeginsFromCurrentState:NO];
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self   cache:YES];
   [UIView commitAnimations];
  [delegate changeImage:self];

 }
 -(void)changeImage:(DraggableImages *)selectedView
 {
count++;
clickCounter++;
counterLable.text=[NSString stringWithFormat:@"%i",clickCounter];
selectedView.image=[images objectAtIndex:selectedView.tag];
if (count==1) {
    firstSelectedView=selectedView;
}
if (count==2) {
    self.view.userInteractionEnabled=NO;
    secondSelectedView=selectedView;
    count=0;
    [self performSelector:@selector(compareImages) withObject:nil     afterDelay:0.7];
}

}
  -(void)compareImages
 {
if (firstSelectedView.tag==secondSelectedView.tag) 
{
    matches++;
    //NSLog(@"%@",matches);
    Score=Score+10;
    scoreLable.text=[NSString stringWithFormat:@"%d",Score];

    firstSelectedView.alpha=0.5;
    secondSelectedView.alpha=0.5;
    self.view.userInteractionEnabled=YES;
    if(matches==[images count])
    {

        [timer invalidate];
        UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:nil message:[NSString stringWithFormat:@"Do you want to countinue?"] delegate:self cancelButtonTitle:nil otherButtonTitles:@"YES",@"NO", nil];
        [alertView show];
        [alertView release];

    } 
}

else {
    Score=Score-1;
    scoreLable.text=[NSString stringWithFormat:@"%d",Score];
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.5];
    [UIView setAnimationBeginsFromCurrentState:NO];
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:firstSelectedView cache:YES];
    firstSelectedView.image=[UIImage imageNamed:@"box.jpg"];
    [UIView commitAnimations];
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.5];
    [UIView setAnimationBeginsFromCurrentState:NO];
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:secondSelectedView cache:YES];
    secondSelectedView.image=[UIImage imageNamed:@"box.jpg"];
    [UIView commitAnimations];
    firstSelectedView.userInteractionEnabled=YES;
    secondSelectedView.userInteractionEnabled=YES;
    self.view.userInteractionEnabled=YES;





}

}

于 2011-09-09T06:05:10.517 回答
0

您需要添加QuartzCore框架,您可以阅读更多关于CABasicAnimation.

一些教程

中断动画进度

基于滑块的图层旋转

CABasicAnimation 基础知识

核心动画路径

于 2011-09-09T06:19:57.920 回答
0

按下按钮后调用此方法:

- (void) animate{

CABasicAnimation *imageRotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
imageRotation.removedOnCompletion = NO; // Do not turn back after anim. is finished
imageRotation.fillMode = kCAFillModeForwards;

imageRotation.toValue = [NSNumber numberWithFloat:((360*M_PI)/180)];

imageRotation.duration = 1.5;
imageRotation.repeatCount = 1;

[yourImageView.layer setValue:imageRotation.toValue forKey:imageRotation.keyPath];
[yourImageView.layer addAnimation:imageRotation forKey:@"imageRotation"];

}

是的,正如 WrightsCS 所说,您需要在项目中包含 QuartzCore 框架。不要忘记导入语句:

#import <QuartzCore/QuartzCore.h>
于 2012-09-28T06:56:37.397 回答