小编Xan*_*ana的帖子

用核心动画旋转UIImageView

我试图做一些相对简单的事情,当用户触摸按钮时使轮子旋转90度,大部分我到目前为止所做的工作是第一次,但此后图像不会移动.我希望它保持新的位置,然后从新位置旋转90度,我有[UIView setAnimationBeginsFromCurrentState:YES];

但这似乎不起作用

我添加了一个NSTimer来"重置"原始图像方向,以便车轮弹回到原始位置,然后在用户触摸它时再次旋转.......但这不是我想要的.

有没有办法使图像保持旋转90度,因此用户的四次触摸会将图像恢复到原始位置.谢谢你的帮助!!

这是示例代码


-(IBAction) rotatewheel:(id)sender {

      [UIView setAnimationDuration:1];
    [UIView setAnimationBeginsFromCurrentState:YES];
    [UIView setAnimationRepeatCount:1];
    wheel.transform = CGAffineTransformMakeRotation(M_PI/4);
    [UIView commitAnimations];  

    returnwheelTimer = [NSTimer scheduledTimerWithTimeInterval:1.1 target:self selector:@selector (returnwheel) userInfo:nil repeats:NO];

}
Run Code Online (Sandbox Code Playgroud)

-(void) returnwheel {

    [UIView beginAnimations:nil context:NULL];

    [UIView setAnimationDuration:.5];
    [UIView setAnimationBeginsFromCurrentState:YES];
    [UIView setAnimationRepeatCount:1];
    wheel.transform = CGAffineTransformMakeRotation(M_PI);
    [UIView commitAnimations];  

}
Run Code Online (Sandbox Code Playgroud)

xcode objective-c ipad ios4

2
推荐指数
1
解决办法
6120
查看次数

标签 统计

ios4 ×1

ipad ×1

objective-c ×1

xcode ×1