0

拖动 UIImageView 时需要有性能/平滑度。在使用Apple 的MoveMe 示例应用程序时,我变得很流畅,但是当我在代码中实现相同功能时,性能会下降。

我也在录制屏幕和音频的视频。我已经在后台保存了视频和音频录制,因此我获得了更多的性能,但它仍然有些痒。

如果您注意到iTunes 上的PuppetpalHD应用程序,它的流畅度非常好。怎么实现???

这是我的代码:

点击按钮:

if (Isrecording ==YES)
{
    [captureview performSelectorInBackground:@selector(startRecording) withObject:nil];
    [self performSelectorInBackground:@selector(startAudioRecording) withObject:nil];
    Isrecording =NO;
    [btnRecord setTitle:@"Stop" forState:UIControlStateNormal];
}
else if (!Isrecording)
{
    [captureview performSelector:@selector(stopRecording) withObject:nil afterDelay:1.0];
    [self performSelector:@selector(stopAudioRecording) withObject:nil afterDelay:3.0];
    Isrecording=YES;
    [btnRecord setTitle:@"Record" forState:UIControlStateNormal];
    [self performSelector:@selector(putTogether) withObject:nil afterDelay:5.0];
}

现在,如果您看到上面的代码,我的 startRecording 函数将记录屏幕。startAudioRecording 将录制音频。

下面的代码用于拖动 UIImageView:

- (void) touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event
{
    UITouch *t = [touches anyObject];
    CGPoint pPrev = [t previousLocationInView:self];
    CGPoint p = [t locationInView:self];

    CGPoint center = self.center;
    center.x += p.x - pPrev.x;
    center.y += p.y - pPrev.y;
    self.center = center;
}

If I stop recording audio or video, then dragging is very smooth. How can I achieve smooth performance along with audio and video recording.

编辑:

我也尝试过使用 http://www.icodeblog.com/2010/10/14/working-with-uigesturerecognizers/ 中给出的 UIPanGestureRecognizer情况与上述相同。我在没有音频和视频录制的情况下获得了足够的平滑度,但是当包含它时,性能会下降......

编辑2:

pointInside:withEvent:与相比有什么性能提升touchesMoved:withEvent:??如何在使用上面的第一种方法时从下面的代码中获得性能?

UITouch *t = [touches anyObject];
CGPoint pPrev = [t previousLocationInView:self];
CGPoint p = [t locationInView:self];

CGPoint center = self.center;
center.x += p.x - pPrev.x;
center.y += p.y - pPrev.y;
self.center = center;

编辑 3:

包括我的屏幕录像代码部分:

-(BOOL) setUpWriter {
NSError* error = nil;
videoWriter = [[AVAssetWriter alloc] initWithURL:[self tempFileURL] fileType:AVFileTypeQuickTimeMovie error:&error];
NSParameterAssert(videoWriter);

//Configure video
NSDictionary* videoCompressionProps = [NSDictionary dictionaryWithObjectsAndKeys:
                                       [NSNumber numberWithDouble:1024.0*1024.0], AVVideoAverageBitRateKey,
                                       nil ];

NSDictionary* videoSettings = [NSDictionary dictionaryWithObjectsAndKeys:
                               AVVideoCodecH264, AVVideoCodecKey,
                               [NSNumber numberWithInt:self.frame.size.width], AVVideoWidthKey,
                               [NSNumber numberWithInt:self.frame.size.height], AVVideoHeightKey,
                               videoCompressionProps, AVVideoCompressionPropertiesKey,
                               nil];

videoWriterInput = [[AVAssetWriterInput assetWriterInputWithMediaType:AVMediaTypeVideo outputSettings:videoSettings] retain];

NSParameterAssert(videoWriterInput);
videoWriterInput.expectsMediaDataInRealTime = YES;
NSDictionary* bufferAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
                                  [NSNumber numberWithInt:kCVPixelFormatType_32ARGB], kCVPixelBufferPixelFormatTypeKey, nil];

avAdaptor = [[AVAssetWriterInputPixelBufferAdaptor assetWriterInputPixelBufferAdaptorWithAssetWriterInput:videoWriterInput sourcePixelBufferAttributes:bufferAttributes] retain];

//add input
[videoWriter addInput:videoWriterInput];
[videoWriter startWriting];
[videoWriter startSessionAtSourceTime:CMTimeMake(0, 1000)];

return YES;
}
4

0 回答 0