CameraViewController.m
上传用户:jjjjag8
上传日期:2017-04-17
资源大小:1443k
文件大小:2k
源码类别:

iPhone

开发平台:

MultiPlatform

  1. //
  2. //  CameraAppDelegate.m
  3. //  Camera
  4. //
  5. //  Created by Jeff LaMarche on 8/8/08.
  6. //  Copyright __MyCompanyName__ 2008. All rights reserved.
  7. //
  8. #import "CameraViewController.h"
  9. @implementation CameraViewController
  10. @synthesize imageView;
  11. @synthesize takePictureButton;
  12. @synthesize selectFromCameraRollButton;
  13. - (void)viewDidLoad {
  14. if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
  15. takePictureButton.hidden = YES;
  16. selectFromCameraRollButton.hidden = YES;
  17. }
  18. }
  19. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
  20. // Return YES for supported orientations
  21. return (interfaceOrientation == UIInterfaceOrientationPortrait);
  22. }
  23. - (void)didReceiveMemoryWarning {
  24. [super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
  25. // Release anything that's not essential, such as cached data
  26. }
  27. - (void)dealloc {
  28. [imageView release];
  29. [takePictureButton release];
  30. [selectFromCameraRollButton release];
  31. [super dealloc];
  32. }
  33. #pragma mark -
  34. - (IBAction)getCameraPicture:(id)sender {
  35. UIImagePickerController *picker = [[UIImagePickerController alloc] init];
  36. picker.delegate = self;
  37. picker.sourceType = (sender == takePictureButton) ? UIImagePickerControllerSourceTypeCamera : UIImagePickerControllerSourceTypeSavedPhotosAlbum;
  38. picker.allowsImageEditing = YES;
  39. [self presentModalViewController:picker animated:YES];
  40. [picker release];
  41. }
  42. - (IBAction)selectExistingPicture {
  43. if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
  44. UIImagePickerController *picker = [[UIImagePickerController alloc] init];
  45. picker.delegate = self;
  46. picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
  47. [self presentModalViewController:picker animated:YES];
  48. [picker release];
  49. }
  50. else {
  51. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error accessing photo library" message:@"Device does not support a photo library" delegate:nil cancelButtonTitle:@"Drat!" otherButtonTitles:nil];
  52. [alert show];
  53. [alert release];
  54. }
  55. }
  56. #pragma mark  -
  57. - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo {
  58. imageView.image = image;
  59. [picker dismissModalViewControllerAnimated:YES];
  60. }
  61. - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
  62. [picker dismissModalViewControllerAnimated:YES];
  63. }
  64. @end