2013-03-07 67 views
-1

到目前为止我的代码是为的UIImageView旋转动画旋转别的

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

回答

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

您设置的@selector(rotateImageView:学位:InTimePeriod :)作为button.The按钮的作用自送他作为第一个参数是@selector(rotateImageView:Degrees:InTimePeriod :)作为默认值,实际上,当函数运行时,* imageView指向按钮,这就是按钮旋转的原因,但是按照aeubanks的说法,imageView.Do。

0

变化

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

[rotateButton addTarget:self action:@selector(rotateImageView) forControlEvents:UIControlEventTouchUpInside]; 
+0

当我尝试,我得到了错误SIGABRT – aeubanks 2013-03-07 02:26:11

+0

在这种情况下,你有一个错误的地方。你可能不应该直接访问imageView,而是这样做:[self rotateImageView:self.imageView Degrees:90 InTimePeriod:1.5]; – 2013-03-07 02:29:11