我有下一个任务:按钮单击图像必须旋转到 90 度。
我的代码是:
#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
@interface ViewController : UIViewController
@property (strong, nonatomic) IBOutlet UIImageView *vector;
@end
=========
@interface ViewController ()
@end
@implementation ViewController
@synthesize vector;
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (IBAction)rotateOn:(id)sender {
[self rotateImage:self.vector duration:2
curve:UIViewAnimationCurveEaseIn degrees:M_PI/2];
}
- (void)rotateImage:(UIImageView *)image duration:(NSTimeInterval)duration
curve:(int)curve degrees:(CGFloat)degrees
{
// Setup the animation
[UIView beginAnimations:NULL context:NULL];
[UIView setAnimationDuration:duration];
[UIView setAnimationCurve:curve];
[UIView setAnimationBeginsFromCurrentState:YES];
[image.layer setAnchorPoint:CGPointMake(0.5,0.5)];
CGAffineTransform transform =
CGAffineTransformMakeRotation(degrees);
image.transform = transform;
[UIView commitAnimations];
}
点击按钮之前我有这个
点击之后
您可以看到该图像旋转到 90 度。但它从起始中心点向下移动。此外,如果我再次单击按钮,则不会发生任何事情。