2016-08-24 70 views
-1

我想獲取旋轉的UIView的屏幕截圖。這是我的代碼UIView UIImage轉換不能正常工作

-(void)rotateImage:(int)radian 
{ 
[UIView beginAnimations:nil context:NULL]; 
[UIView setAnimationDuration:0.3]; 
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn]; 
[UIView setAnimationBeginsFromCurrentState:YES]; 

// The transform matrix 
CGAffineTransform transform = CGAffineTransformRotate(self.baseImageView.transform, M_PI/2 * radian); 
self.baseImageView.transform = transform; 
} 

-(NSData *)getData 
{ 

UIGraphicsBeginImageContextWithOptions(self.bounds.size, NO,0.0); 
[self.layer renderInContext:UIGraphicsGetCurrentContext()]; 
UIImage * img = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 
return UIImageJPEGRepresentation(img, 1.0); 
} 

截圖成功創建,但在那之後所有目前我viewcontrollers從左上角介紹和意見反彈&胡作非爲。但是,如果我創建屏幕截圖而不旋轉圖像一切都很好。我堅持任何幫助表示讚賞。

注:我已經嘗試修改UIGraphicsBeginImageContextWithOptions參數。我的項目不使用ARC。

+4

你曾經調用'[UIView commitAnimations];'? – beyowulf

+0

無關但爲什麼不使用ARC?這太愚蠢了。 – rmaddy

+0

爲什麼你使用'beginAnimations'?這就像你住在iOS 3. – matt

回答

0

事實證明,動畫處理不當。我最終這樣做來解決問題。

[UIView animateWithDuration:0.25 delay:0 options:UIViewAnimationCurveEaseIn animations:^{ 
    CGAffineTransform transform = CGAffineTransformRotate(self.baseImageView.transform, M_PI/2 * radian); 
    self.baseImageView.transform = transform; 
} completion:nil];