我想在录像机上显示剩余时间。目前正在显示录制时间。我怎么样?
我的代码是:
UIImagePickerController* Videopicker1 = [[UIImagePickerController alloc] init];
Videopicker1.delegate = self;
Videopicker1.sourceType = UIImagePickerControllerSourceTypeCamera;
Videopicker1.showsCameraControls = YES;
Videopicker1.videoQuality=UIImagePickerControllerQualityTypeLow;
Videopicker1.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeMovie]; // kUTTypeMovie is actually an NSString.
Videopicker1.videoMaximumDuration = 30.0f; // limits video length to 30 seconds.
[self presentModalViewController:Videopicker1 animated:YES];
提前致谢。
答案 0 :(得分:3)
在VC.h文件上
@interface VideoCaptureVC_iPhone : UIViewController
<UIActionSheetDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate>
{
UIImagePickerController *picker;
NSTimer *videoTimer;
}
@property (nonatomic, retain) NSTimer *videoTimer;
在您的vc.m文件
上- (void)pickerCameraSnap:(id)sender{
NSLog(@"start camera capture and timer");
[picker startVideoCapture];
self.videoTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(changeValue) userInfo:nil repeats:YES];
}
根据您的需要进行计算,并在适当的位置更改文本@“TimeRemaining” 我已经为景观视图旋转了文字!
-(void)changeValue{
UILabel *textNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(30, 30, 100, 100)];
textNameLabel.center = CGPointMake(30,285);
textNameLabel.backgroundColor = [UIColor redColor];
textNameLabel.text = @"TimeRemaining";
textNameLabel.textColor = [UIColor whiteColor];
CGAffineTransform transformRotate = CGAffineTransformMakeRotation((M_PI / 2));
textNameLabel.transform = transformRotate;
UIView *myOverlay = [[UIView alloc] initWithFrame:self.view.bounds];
UIImage *overlayImg = [UIImage imageNamed:@"CameraOverlay"];
UIImageView *overlayBg;
overlayBg = [[UIImageView alloc] initWithImage:overlayImg];
[myOverlay addSubview:overlayBg];
[myOverlay addSubview:textNameLabel];
[picker setCameraOverlayView:myOverlay];
}
最后停止计时器
- (void)stopCamera:(id)sender{
NSLog(@"stop camera");
[self.videoTimer invalidate];
[picker stopVideoCapture];
[picker setCameraDevice:UIImagePickerControllerCameraDeviceRear];
}
答案 1 :(得分:0)
由于您设置了视频最长时间,并且您声明当前正在显示当前持续时间。
TimeRemaining = videoMaximumDuration - currentDuration;