到目前爲止我的代碼是爲的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旋轉?
當我嘗試,我得到了錯誤SIGABRT – aeubanks 2013-03-07 02:26:11
在這種情況下,你有一個錯誤的地方。你可能不應該直接訪問imageView,而是這樣做:[self rotateImageView:self.imageView Degrees:90 InTimePeriod:1.5]; – 2013-03-07 02:29:11