-1

到目前为止我的代码是

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 旋转?

4

2 回答 2

0

改变

    [rotateButton addTarget:self action:@selector(rotateImageView:Degrees:InTimePeriod:) forControlEvents:UIControlEventTouchUpInside];

    [rotateButton addTarget:self action:@selector(rotateImageView) forControlEvents:UIControlEventTouchUpInside];
于 2013-03-07T01:56:01.520 回答
0
 [rotateButton addTarget:self action:@selector(rotateImageView:Degrees:InTimePeriod:) forControlEvents:UIControlEventTouchUpInside];

您将@selector(rotateImageView:Degrees:InTimePeriod:) 设置为按钮的操作。按钮将自己作为@selector(rotateImageView:Degrees:InTimePeriod:) 的第一个参数默认发送给他,事实上,当函数是运行时,*imageView 指向按钮,这就是按钮旋转但 imageView.Do 正如 aeubanks 所说的原因。

于 2013-03-07T02:09:20.460 回答