iPhone4中iOS7中怪异的UIScrollview行为
我正在开发一个与视频相关的应用程序。为此,我使用了iPhone4中iOS7中怪异的UIScrollview行为,ios,iphone,ios7,uiscrollview,avfoundation,Ios,Iphone,Ios7,Uiscrollview,Avfoundation,我正在开发一个与视频相关的应用程序。为此,我使用了AVFoundation框架来捕获图像和视频。我正在捕获一个图像并在下一个视图中显示该捕获的图像,其中图像视图是子视图到滚动视图。在iPhone5、iPhone5s和iPad中都可以正常工作,但在iPhone4中,在捕获图像并连接到scrollView后,应用程序的速度变慢了。滚动视图不像在其他设备中那样平滑滚动。我并没有发现问题出在哪里。我正在使用以下代码捕获图像: -(void)capturePhoto { _ciContext =
AVFoundation
框架来捕获图像和视频。我正在捕获一个图像并在下一个视图中显示该捕获的图像,其中图像视图是子视图
到滚动视图
。在iPhone5、iPhone5s和iPad中都可以正常工作,但在iPhone4中,在捕获图像并连接到scrollView
后,应用程序的速度变慢了。滚动视图不像在其他设备中那样平滑滚动。我并没有发现问题出在哪里。我正在使用以下代码捕获图像:
-(void)capturePhoto
{
_ciContext = [CIContext contextWithOptions:nil];
AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
// - input
AVCaptureDeviceInput *deviceInput = [AVCaptureDeviceInput deviceInputWithDevice:device error:NULL];
NSError *error = nil;
if ([device lockForConfiguration:&error])
{
if ([device isFlashModeSupported:AVCaptureFlashModeOff])
{
device.flashMode = AVCaptureFlashModeOff;
}
[device unlockForConfiguration];
}
// - output
_dataOutput = [[AVCaptureStillImageOutput alloc] init];
NSDictionary *outputSettings = [[NSDictionary alloc] initWithObjectsAndKeys:
AVVideoCodecJPEG, AVVideoCodecKey, nil];
_dataOutput.outputSettings = outputSettings;
// - output
NSMutableDictionary *settings;
settings = [NSMutableDictionary dictionary];
[settings setObject:[NSNumber numberWithInt:kCVPixelFormatType_32BGRA]
forKey:(__bridge id) kCVPixelBufferPixelFormatTypeKey];
_dataOutputVideo = [[AVCaptureVideoDataOutput alloc] init];
_dataOutputVideo.videoSettings = settings;
[_dataOutputVideo setSampleBufferDelegate:self queue:dispatch_get_main_queue()];
_session = [[AVCaptureSession alloc] init];
[_session addInput:deviceInput];
[_session addOutput:_dataOutput];
[_session addOutput:_dataOutputVideo];
// _session.sessionPreset = AVCaptureSessionPresetPhoto;
_session.sessionPreset = AVCaptureSessionPresetHigh;
// _session.sessionPreset = AVCaptureSessionPresetMedium;
[_session startRunning];
// add gesture
// UIGestureRecognizer *gr = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didTapGesture:)];
// gr.delegate = self;
// [self.touchView addGestureRecognizer:gr];
_focusView = [[UIView alloc] init];
CGRect imageFrame = _focusView.frame;
imageFrame.size.width = 80;
imageFrame.size.height = 80;
_focusView.frame = imageFrame;
_focusView.center = CGPointMake(160, 202);
CALayer *layer = _focusView.layer;
layer.shadowOffset = CGSizeMake(2.5, 2.5);
layer.shadowColor = [[UIColor blackColor] CGColor];
layer.shadowOpacity = 0.5;
layer.borderWidth = 2;
layer.borderColor = [UIColor yellowColor].CGColor;
[self.touchView addSubview:_focusView];
_focusView.alpha = 0;
_isShowFlash = NO;
[self.view bringSubviewToFront:self.touchView];
UIView *footerView = [self.view viewWithTag:2];
[self.view bringSubviewToFront:footerView];
}
稍后,我将附加到滚动视图,如下所示:
scrollImgView=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 340)];
UIImage *image = [UIImage imageWithData:appdelegate.capturedImgData];
UIImage *tempImage=[self resizeImage:image withWidth:320 withHeight:340];
NSData *imgData=UIImageJPEGRepresentation(tempImage,1.0);//0.25f
NSLog(@"image is %@",image);
scrollImgView.image=[UIImage imageWithData:imgData];
// scrollImgView.contentMode = UIViewContentModeScaleAspectFit;
// UIViewContentModeScaleAspectFit;
[postScrollView addSubview:scrollImgView];
如果有人遇到同样的问题,请给我一些建议。您的编码很好,而且在设备中也不是问题,可能会发生
1. network problem
2. device memory is already loaded fully.
3. some Data conversation also taken times
这里
在我的建议中
1. use `Asychronous method`
-- sdwebimage
-- Asychronous Imageview
-- NSOperation_Queue
-- Dispatch im main_queue
使用任何人的这个,它将采取一些回应你。我的建议是使用
SDWebImage
。。使用此链接我通过更改
\u session.sessionPreset=AVCaptureSessionPresetHigh
至
_session.sessionPreset = AVCaptureSessionPresetMedium
_session.sessionPreset = AVCaptureSessionPresetMedium