到目前为止我的代码是
rotateButton = [UIButton new];
rotateButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[rotateButton setFrame:CGRectMake(334, 80, 100, 20)];
[rotateButton addTarget:self action:@selector(rotateImageView:Degrees:InTimePeriod:) forControlEvents:UIControlEventTouchUpInside];
[rotateButton setTitle:@"Rotate" forState:UIControlStateNormal];
[self.view addSubview:rotateButton];
-(void)rotateImageView
{
[self rotateImageView:imageView Degrees:90 InTimePeriod:1.5];
}
-(void)rotateImageView:(UIImageView*)imageView Degrees:(NSInteger)degrees InTimePeriod:(float)time
{
CABasicAnimation *rotate;
rotate = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
rotate.fromValue = [NSNumber numberWithFloat:0];
rotate.toValue = [NSNumber numberWithFloat:DEGREES_TO_RADIANS(degrees)];
rotate.duration = time;
rotate.repeatCount = 1;
[imageView.layer addAnimation:rotate forKey:@"Rotate"];
}
但是,我用来开始旋转的按钮是我按下按钮后旋转的对象,而不是我希望它旋转的 imageView。如何使 imageView 旋转?