사진을 찍어서 캡처하고 uiimage보기로 표시하려고하거나 동영상을 캡처하여 영화관 컨트롤러에서 다시 재생하려고합니다.iOS 기기에서 사진 및 동영상 찍기
나는 단추를 클릭 할 수 있으며, 내 uiimageview에 잘 표시되는 "사진 찍기"가 가능합니다. 그러나 "Take Video"버튼을 클릭하면 uiimageview에서 이미지가 사라집니다. Take 비디오는 작동하고 화면은 괜찮지 만 내 uiimage는 이제 사라졌습니다.
내가 다시 찍은 사진을 찍으면 내가 캡처 한 비디오가 사라 집니까?
.H 파일
#import <UIKit/UIKit.h>
#import <MediaPlayer/MediaPlayer.h>
#import <MobileCoreServices/MobileCoreServices.h>
@interface addEventViewController : UIViewController<UIImagePickerControllerDelegate, UINavigationControllerDelegate>{
UIImagePickerController *imagePicker;
UIImage *eventPhoto;
IBOutlet UIImageView *imageView;
}
-(IBAction)TakePhoto;
- (IBAction)takeVideo:(id)sender;
@property (copy, nonatomic) NSURL *movieURL;
@property (strong, nonatomic) MPMoviePlayerController *movieController;
@end
하는 .m 파일
#import "addEventViewController.h"
@interface addEventViewController(){
}
@end
@implementation addEventViewController
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
// FOR THE TAKE PHOTO
eventPhoto = [info objectForKey:UIImagePickerControllerOriginalImage];
[imageView setImage: eventPhoto];
[self dismissViewControllerAnimated:YES completion:NULL];
// FOR THE TAKE VIDEO
self.movieURL = info[UIImagePickerControllerMediaURL];
[picker dismissViewControllerAnimated:YES completion:NULL];
}
-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
//FOR THE TAKE PHOTO
[self dismissViewControllerAnimated:YES completion:NULL];
// FOR THE TAKE VIDEO
[picker dismissViewControllerAnimated:YES completion:NULL];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
// TAKE PHOTO BUTTON
-(IBAction)TakePhoto{
imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
[imagePicker setSourceType: UIImagePickerControllerSourceTypeCamera];
[self presentViewController: imagePicker animated:YES completion:NULL];
}
// TAKE VIDEO BUTTON
- (IBAction)takeVideo:(UIButton *)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie, nil];
[self presentViewController:picker animated:YES completion:NULL];
}
- (void)viewDidAppear:(BOOL)animated {
self.movieController = [[MPMoviePlayerController alloc] init];
[self.movieController setContentURL:self.movieURL];
[self.movieController.view setFrame:CGRectMake (420, 76, 320, 200)];
[self.view addSubview:self.movieController.view];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:self.movieController];
[self.movieController play];
}
- (void)moviePlayBackDidFinish:(NSNotification *)notification {
[[NSNotificationCenter defaultCenter]removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end