CameraViewController.m
上传用户:jjjjag8
上传日期:2017-04-17
资源大小:1443k
文件大小:2k
源码类别:
iPhone
开发平台:
MultiPlatform
- //
- // CameraAppDelegate.m
- // Camera
- //
- // Created by Jeff LaMarche on 8/8/08.
- // Copyright __MyCompanyName__ 2008. All rights reserved.
- //
- #import "CameraViewController.h"
- @implementation CameraViewController
- @synthesize imageView;
- @synthesize takePictureButton;
- @synthesize selectFromCameraRollButton;
- - (void)viewDidLoad {
- if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
- takePictureButton.hidden = YES;
- selectFromCameraRollButton.hidden = YES;
- }
- }
- - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
- // Return YES for supported orientations
- return (interfaceOrientation == UIInterfaceOrientationPortrait);
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
- // Release anything that's not essential, such as cached data
- }
- - (void)dealloc {
- [imageView release];
- [takePictureButton release];
- [selectFromCameraRollButton release];
- [super dealloc];
- }
- #pragma mark -
- - (IBAction)getCameraPicture:(id)sender {
- UIImagePickerController *picker = [[UIImagePickerController alloc] init];
- picker.delegate = self;
- picker.sourceType = (sender == takePictureButton) ? UIImagePickerControllerSourceTypeCamera : UIImagePickerControllerSourceTypeSavedPhotosAlbum;
- picker.allowsImageEditing = YES;
- [self presentModalViewController:picker animated:YES];
- [picker release];
- }
- - (IBAction)selectExistingPicture {
- if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
- UIImagePickerController *picker = [[UIImagePickerController alloc] init];
- picker.delegate = self;
- picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
- [self presentModalViewController:picker animated:YES];
- [picker release];
- }
- else {
- UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error accessing photo library" message:@"Device does not support a photo library" delegate:nil cancelButtonTitle:@"Drat!" otherButtonTitles:nil];
- [alert show];
- [alert release];
- }
- }
- #pragma mark -
- - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo {
- imageView.image = image;
- [picker dismissModalViewControllerAnimated:YES];
- }
- - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
- [picker dismissModalViewControllerAnimated:YES];
- }
- @end