You are on page 1of 8

UICollectionView,

Camera
5. predavanje

UICollectionView

Slican je UITableView kontroli

grid layout, umesto liste, i mnogo je fleksibilniji

Definisan od strane UICollectionFlowLayout-a

Neophodna je custom UICollectionViewCell

Zahteva Datasource i Delegate

Cell selection

didSelect / didDeselect delegate metode

didHighlight / didUnhighlight delegate metode

UICollectionViewCell ima highlight i background viewove

cell.contentView

cell.backgroundView

cell.selectedBackgroundView

Layout

Default FlowLayout

Setup u Storyboard-u

Custom layouts? (https://www.youtube.com/watch?


v=8vB2TMS2uhE)

Kamera

UIImagePickerController

UIImagePickerControllerDelegate,
UINavigationControllerDelegate

Provera da li postoji kamera

Fotkanje kamerom

Odabir slike iz camera roll-a

Da li device ima kameru?


if (![UIImagePickerController
isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:@"Error"
message:@"Device has no camera"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles: nil];
[myAlertView show];
}

- (IBAction)takePhoto:(UIButton *)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker animated:YES completion:NULL];
}
- (IBAction)selectPhoto:(UIButton *)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:NULL];
}

#pragma mark - Image Picker Controller delegate methods


- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
self.imageView.image = chosenImage;
[picker dismissViewControllerAnimated:YES completion:NULL];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker dismissViewControllerAnimated:YES completion:NULL];
}

You might also like