It looks like you're new here. If you want to get involved, click one of these buttons!
@class ScrollViewController;
@interface ViewController : UIViewController <UIImagePickerControllerDelegate> {
UIButton *takePictureButton;
UIImageView *imageView;
ScrollViewController *scrollViewController;
UIImageView *currentPicture;
}
@property (nonatomic, retain) IBOutlet UIImageView *imageView;
@property (nonatomic, retain) ScrollViewController *scrollViewController;
@property (nonatomic, retain) IBOutlet UIImageView *currentPicture;
-(IBAction)getCameraPicture:(id)sender;
-(IBAction)selectExistingPicture;
@end
@implementation ViewController
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad {
if (![UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeCamera]) {
takePictureButton.hidden = YES;
}
}
#pragma mark -
// Camera
-(IBAction)getCameraPicture:(id)sender {
UIImagePickerController *picker =
[[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsImageEditing = NO;
picker.sourceType = (sender == takePictureButton) ?
UIImagePickerControllerSourceTypeCamera :
UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[self presentModalViewController:picker animated:YES];
[picker release];
}
// Photo Library
-(IBAction)selectExistingPicture {
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
UIImagePickerController *picker =
[[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsImageEditing = NO;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:picker animated:YES];
[picker release];
}
else {
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@\"Error acessing Photo Library\"
message:@\"Deice does not support a Photo Library\"
delegate:nil
cancelButtonTitle:@\"Dismiss\"
otherButtonTitles:nil];
[alert show];
[alert release];
}
}
#pragma mark -
-(void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingImage:(UIImage *)image
editingInfo:(NSDictionary *)editingInfo {
imageView.image = image;
[picker dismissModalViewControllerAnimated:YES];
self.currentPicture = [image copy];
[self dismissModalViewControllerAnimated:YES];
[self goNext];
self.currentPicture = image;
}
-(void)goNext{
ScrollViewController *vc = [[ScrollViewController alloc] initWithNibName:@\"Second\" bundle:nil];
[vc giveMePicture:currentPicture];
[self.navigationController pushViewController:vc animated:YES];
}
-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker dismissModalViewControllerAnimated:YES];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight;}
@end