ALL challenges


#1

Hello all, here is how i did the challenges

Bronze Challenge
In the takePicture: method, set the property of the imagePickerController to allow editing

Now, this makes the info dictionary (handed to you in the delegate method -(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
The info dictionary contain the edited image, so you need to get that one instead of the original, so change this
From this

To this

That’s it.

Silver Challenge
First, add another bar button item in the xib file, next to the camera button. Have it call a method, just like we did with the camera. Below is how i implemented the method to delete the image

[code]- (IBAction)clearImage:(id)sender {

// Set the pointer to nill in BNRImageStore & in BNRItem, and then set the image property of the image view to nil

// Call the delete method on sharedStore and have it delete the image that corrosponds to the selected item
[[BNRImageStore sharedStore] deleteImageforKey:[item imageKey]];

// Remove the item key
[item setImageKey:nil];

// Remove image in UIImageView
[imageView setImage:nil];

}[/code]

Gold Challenge
This code is added when presenting the imagePickerController, in the takePicture method

[code] // First, get the image from the files
UIImageView *crosshair = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@“crossHair”]];

// Make it a bit transparent to it doesn't cover the image
[crosshair setAlpha:0.5];

// Make it fill up the entire view (it's a big crosshair) :)
[crosshair setFrame:[imagePicker.view frame]];
[imagePicker setCameraOverlayView:crosshair];

// If you are working with a small crosshair, you need to place it in the middle, and you can do that by getting the center of the imagePicker's view (either by the center property of dividing the width and height by 2), but, that might cause problems cause the crosshair would still be a little out, so after the frame have been set on the crosshair, set it's CENTER property to be the center of the parent view, THAT will make it appear in the middle :)
//but by doing what i did above (have the crosshair take up the entire view) is easier.

}[/code]

Note: I got an image of a crosshair named crossHair.png in my project.

Hope it helps :slight_smile:
My programming forum for beginners angryteds.com/?page_id=131


#2

Thanks for your code. I love your code from other chapters as well. Short, precise, and easy to understand! Really Thanks,


#3

Great job,
but i guess you missed to control the data source, because you can access cameraOverlayView only when the source type of the image picker is set to UIImagePickerControllerSourceTypeCamera.

[code] if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
[crosshair setFrame:[imagePicker.view frame]];

    [imagePicker setCameraOverlayView:crosshair];
}[/code]