Permalink
Browse files

Making app universal, first cut

  • Loading branch information...
1 parent f6f00ab commit 8c85ed2bed335e4a7ac009c654b30194c007b0c9 Ryan Blunden committed Jan 16, 2013
@@ -300,7 +300,9 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "Homepwner/Homepwner-Prefix.pch";
INFOPLIST_FILE = "Homepwner/Homepwner-Info.plist";
+ IPHONEOS_DEPLOYMENT_TARGET = 6.0;
PRODUCT_NAME = "$(TARGET_NAME)";
+ TARGETED_DEVICE_FAMILY = "1,2";
WRAPPER_EXTENSION = app;
};
name = Debug;
@@ -311,7 +313,9 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "Homepwner/Homepwner-Prefix.pch";
INFOPLIST_FILE = "Homepwner/Homepwner-Info.plist";
+ IPHONEOS_DEPLOYMENT_TARGET = 6.0;
PRODUCT_NAME = "$(TARGET_NAME)";
+ TARGETED_DEVICE_FAMILY = "1,2";
WRAPPER_EXTENSION = app;
};
name = Release;
@@ -10,6 +10,7 @@
@class BNRItem;
-@interface DetailViewController : UIViewController <UIImagePickerControllerDelegate, UITextFieldDelegate, UINavigationControllerDelegate>
+@interface DetailViewController : UIViewController <UIImagePickerControllerDelegate, UITextFieldDelegate,
+ UINavigationControllerDelegate, UIPopoverControllerDelegate>
@property (nonatomic, strong) BNRItem *item;
@end
@@ -10,15 +10,17 @@
#import "BNRItem.h"
#import "BNRImageStore.h"
-@interface DetailViewController ()
+@interface DetailViewController () {
+ UIPopoverController *_imagePickerPopover;
+}
@property(weak, nonatomic) IBOutlet UITextField *nameField;
@property(weak, nonatomic) IBOutlet UITextField *serialField;
@property(weak, nonatomic) IBOutlet UITextField *valueField;
@property(weak, nonatomic) IBOutlet UILabel *dateLabel;
@property(weak, nonatomic) IBOutlet UIToolbar *toolbarView;
@property(weak, nonatomic) IBOutlet UIImageView *imageView;
-@property (weak, nonatomic) IBOutlet UIButton *deletePictureButton;
+@property(weak, nonatomic) IBOutlet UIButton *deletePictureButton;
- (IBAction)backgroundTapped:(id)sender;
@@ -51,11 +53,12 @@ - (IBAction)deletePicture:(id)sender {
[[BNRImageStore sharedStore] removeImageForKey:[[self item] imageKey]];
[[self item] setImageKey:nil];
[[self imageView] setImage:nil];
- [[self deletePictureButton] setHidden:TRUE];
+ //[[self deletePictureButton] setHidden:TRUE];
}
- (IBAction)backgroundTapped:(id)sender {
[[self view] endEditing:YES];
+ [[self nameField] exerciseAmbiguityInLayout];
}
- (void)viewWasSingleFingerTapped {
@@ -66,13 +69,64 @@ - (void)viewWasSingleFingerTapped {
- (void)viewDidLoad {
[super viewDidLoad];
- // The other way to achieve this is to have the view be a type of class UIControl
- // That way, it can send the message "backgroundTapped" to its delegate
- //
- //UIGestureRecognizer *singleFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self
- // action:@selector
- // (viewWasSingleFingerTapped)];
- //[[self view] addGestureRecognizer:singleFingerTap];
+
+ UIImageView *iv = [[UIImageView alloc] initWithImage:nil];
+
+ // The contentMode of the image view in the XIB was Aspect Fit:
+ [iv setContentMode:UIViewContentModeScaleAspectFit];
+
+ [iv setTranslatesAutoresizingMaskIntoConstraints:NO];
+
+ // The image view was a subview of the view
+ [[self view] addSubview:iv];
+
+ // The image view was pointed to by the _imageView instance variable
+ [self setImageView:iv];
+
+ NSLayoutConstraint *topConstraint = [NSLayoutConstraint constraintWithItem:[self imageView]
+ attribute:NSLayoutAttributeTop
+ relatedBy:NSLayoutRelationEqual
+ toItem:[self dateLabel]
+ attribute:NSLayoutAttributeBottom
+ multiplier:1.0
+ constant:0.0];
+
+ [[self view] addConstraint:topConstraint];
+
+ NSLayoutConstraint *leftConstraint = [NSLayoutConstraint constraintWithItem:[self imageView]
+ attribute:NSLayoutAttributeLeading
+ relatedBy:NSLayoutRelationEqual
+ toItem:[self view]
+ attribute:NSLayoutAttributeLeading
+ multiplier:1
+ constant:0];
+ [[self view] addConstraint:leftConstraint];
+
+ NSLayoutConstraint *rightConstraint = [NSLayoutConstraint constraintWithItem:[self imageView]
+ attribute:NSLayoutAttributeTrailing
+ relatedBy:NSLayoutRelationEqual
+ toItem:[self view]
+ attribute:NSLayoutAttributeTrailing
+ multiplier:1
+ constant:0];
+ [[self view] addConstraint:rightConstraint];
+
+ NSLayoutConstraint *bottomConstraint = [NSLayoutConstraint constraintWithItem:[self imageView]
+ attribute:NSLayoutAttributeBottom
+ relatedBy:NSLayoutRelationEqual
+ toItem:[self toolbarView]
+ attribute:NSLayoutAttributeTop
+ multiplier:1.0
+ constant:0];
+ [[self view] addConstraint:bottomConstraint];
+}
+
+- (void)viewDidLayoutSubviews {
+ for (UIView *v in [[self view] subviews]) {
+ if ([v hasAmbiguousLayout]) {
+ NSLog(@"AMIGUOUS: %@", v);
+ }
+ }
}
- (void)viewWillAppear:(BOOL)animated {
@@ -96,10 +150,11 @@ - (void)viewWillAppear:(BOOL)animated {
if (imageKey) {
UIImage *imageToDisplay = [[BNRImageStore sharedStore] imageForKey:imageKey];
[[self imageView] setImage:imageToDisplay];
+// [[self deletePictureButton] setHidden:YES];
}
else {
[[self imageView] setImage:nil];
- [[self deletePictureButton] setHidden:YES];
+// [[self deletePictureButton] setHidden:YES];
}
}
@@ -135,8 +190,32 @@ - (BOOL)findAndResignFirstResponder {
}
- (IBAction)takePicture:(id)sender {
+
+ if ([_imagePickerPopover isPopoverVisible]) {
+ // If the popover is already up, get rid of it
+ [_imagePickerPopover dismissPopoverAnimated:YES];
+ _imagePickerPopover = nil;
+ return;
+ }
+
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
+ // Place image picker on the screen
+ // Check for iPad device before instantiating the popover controller
+ if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
+ // Create a new popover controller that will display the imagePicker
+ _imagePickerPopover = [[UIPopoverController alloc] initWithContentViewController:imagePicker];
+ [_imagePickerPopover setDelegate:self];
+
+ // Display the popover controller; sender is the camera bar button item
+ [_imagePickerPopover presentPopoverFromBarButtonItem:sender
+ permittedArrowDirections:UIPopoverArrowDirectionAny
+ animated:YES];
+ }
+ else {
+ [self presentViewController:imagePicker animated:YES completion:nil];
+ }
+
// If our devices has a camera, we want to take a picture, otherwise, we just pick from the photo library
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
[imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
@@ -146,9 +225,6 @@ - (IBAction)takePicture:(id)sender {
}
[imagePicker setDelegate:self];
-
- // place image picker on the screen
- [self presentViewController:imagePicker animated:YES completion:nil];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
@@ -170,11 +246,22 @@ - (void)imagePickerController:(UIImagePickerController *)picker didFinishPicking
[[BNRImageStore sharedStore] setImage:image forKey:key];
// Put that image onto the screen in our image view
- [[self deletePictureButton] setHidden:NO];
+// [[self deletePictureButton] setHidden:NO];
[[self imageView] setImage:image];
- // Take image picker off the screen - you must call this dismiss method
- [self dismissViewControllerAnimated:YES completion:nil];
+ if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
+ // On phone, image picker is presented modally. Dismiss it
+ [self dismissViewControllerAnimated:YES completion:nil];
+ }
+ else {
+ [_imagePickerPopover dismissPopoverAnimated:YES];
+ _imagePickerPopover = nil;
+ }
+}
+
+- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController {
+ NSLog(@"User dismissed popover");
+ _imagePickerPopover = nil;
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
Oops, something went wrong.

0 comments on commit 8c85ed2

Please sign in to comment.