0
我想將圖像旋轉90度。一切正常。但動畫運行不順暢?用動畫旋轉圖像?
旋轉編碼
- (void)rotatePhoto {
UIImage *rotatedImage;
if (finalImage.imageOrientation == UIImageOrientationRight)
rotatedImage = [[UIImage alloc] initWithCGImage: finalImage.CGImage
scale: 1.0
orientation: UIImageOrientationDown];
else if (finalImage.imageOrientation == UIImageOrientationDown)
rotatedImage = [[UIImage alloc] initWithCGImage: finalImage.CGImage
scale: 1.0
orientation: UIImageOrientationLeft];
else if (finalImage.imageOrientation == UIImageOrientationLeft)
rotatedImage = [[UIImage alloc] initWithCGImage: finalImage.CGImage
scale: 1.0
orientation: UIImageOrientationUp];
else
rotatedImage = [[UIImage alloc] initWithCGImage: finalImage.CGImage
scale: 1.0
orientation: UIImageOrientationRight];
[self updateImageViewAnimated:rotatedImage]
}
我已經試過類似的東西,但它並不順利。它的旋轉,但我不明白
- (void) updateImageViewAnimated:(UIImage *)image
{
CABasicAnimation* rotationAnimation;
rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI /2];
rotationAnimation.duration = 0.7;
rotationAnimation.cumulative = YES;
[_finalImageView.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
[UIView transitionWithView:_finalImageView
duration:0.7 options:UIViewAnimationOptionTransitionNone
animations:^{
_finalImageView.image = image;
} completion:NULL];
}
但是,如果只應用旋轉變換,那麼我將旋轉imageview。但我也想獲得旋轉的imagenad保存這個旋轉的圖像到文檔目錄......隨着旋轉變換我會得到90度的旋轉圖像? – Mahavir
不,旋轉圖像視圖不會改變底層圖像。但是,你可以有_separate_代碼來派生底層圖像的旋轉版本,以便保存它。 – matt
好吧然後我將首先應用旋轉變換的視圖與動畫和動畫停止後,我將設置旋轉的圖像到圖像視圖。我對嗎? – Mahavir