我正在使用avcapturesession捕获图像,然后将其发送到我的服务器。
[self.stillImageOutput captureStillImageAsynchronouslyFromConnection:videoConnection completionHandler: ^(CMSampleBufferRef imageSampleBuffer, NSError *error) {
if (imageSampleBuffer != NULL) {
NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageSampleBuffer];
self.videoImageData = [imageData copy];
[self processImage:[UIImage imageWithData:imageData]];
NSString* response=[self uploadImage];
[activityIndicator removeFromSuperview];
self.takePictureBtn.enabled = YES;
[self setUserMessage:response];
}
}];
- (void) processImage:(UIImage *)image
{
...
[UIView beginAnimations:@"rotate" context:nil];
[UIView setAnimationDuration:0.5];
int degrees = [self rotationDegrees];
CGFloat radians =degrees * M_PI / 180.0;
self.captureImageView.transform = CGAffineTransformMakeRotation(radians);
[UIView commitAnimations];
[self.captureImageView setNeedsDisplay];
}
- (NSString*)uploadImage
将照片发送到服务器
我期望的行为是在ProcessImage终止终止之后,该图像将显示在其上的UIImageView captureImageView
中,活动指示器旋转,但我在指示器旋转时获得了一个白色的blanc视图,并且仅在服务器post post post post terminates终止captureImageView
显示图像
我如何实现自己所需的行为?
我面对的另一个问题 是我的imakes ampamplebuffer返回了一个拍摄的镜像图像(左侧的对象出现在右侧)
<)来自文档:
此方法使 请求的注释并立即返回。视图不是 实际重新绘制直到下一个绘图周期,此时全部 无效的视图已更新。
由于您打电话给setNeedsDisplay
后您正在做其他事情,因此活动不会结束,并且您不会立即获得显示。
如果您想做更多的事情,一种方法是将其余的东西安排在新块中,例如
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
NSString *const response = [self uploadImage];
[activityIndicator removeFromSuperview];
self.takePictureBtn.enabled = YES;
[self setUserMessage:response];
}];