diff --git a/WordPress/Classes/PostSettingsViewController.h b/WordPress/Classes/PostSettingsViewController.h index bbac86f9f7c4..a1b19aeed908 100644 --- a/WordPress/Classes/PostSettingsViewController.h +++ b/WordPress/Classes/PostSettingsViewController.h @@ -6,6 +6,7 @@ #import "CPopoverManager.h" #import "PostAnnotation.h" #import "UIImageView+AFNetworking.h" +#import "QuickPicturePreviewView.h" // the amount of vertical shift upwards keep the text field in view as the keyboard appears #define kOFFSET_FOR_KEYBOARD 150.0 @@ -46,7 +47,7 @@ NSString *address; BOOL isUpdatingLocation, isUploadingFeaturedImage; IBOutlet UILabel *visibilityTitleLabel, *statusTitleLabel, *postFormatTitleLabel, *featuredImageLabel; - IBOutlet UIImageView *featuredImageView; + IBOutlet QuickPicturePreviewView *featuredImageView; IBOutlet UITableViewCell *featuredImageTableViewCell; IBOutlet UIActivityIndicatorView *featuredImageSpinner; } @@ -55,11 +56,11 @@ @property (nonatomic, strong) IBOutlet UITableViewCell *postFormatTableViewCell; - (id)initWithPost:(AbstractPost *)aPost; - - (void)reloadData; - (void)endEditingAction:(id)sender; - (UITableViewCell*) getGeolactionCellWithIndexPath: (NSIndexPath*)indexPath; - (void)featuredImageUploadFailed: (NSNotification *)notificationInfo; - (void)featuredImageUploadSucceeded: (NSNotification *)notificationInfo; - (void)showFeaturedImageUploader: (NSNotification *)notificationInfo; + @end diff --git a/WordPress/Classes/PostSettingsViewController.m b/WordPress/Classes/PostSettingsViewController.m index f0418dc9fbd5..55cf7cb5e24c 100644 --- a/WordPress/Classes/PostSettingsViewController.m +++ b/WordPress/Classes/PostSettingsViewController.m @@ -19,6 +19,7 @@ @interface PostSettingsViewController () { } @property (nonatomic, strong) AbstractPost *apost; + - (void)showPicker:(UIView *)picker; - (void)geocodeCoordinate:(CLLocationCoordinate2D)c; - (void)geolocationCellTapped:(NSIndexPath *)indexPath; @@ -27,6 +28,7 @@ - (void)loadFeaturedImage:(NSURL *)imageURL; @end @implementation PostSettingsViewController + @synthesize postDetailViewController, postFormatTableViewCell; #pragma mark - @@ -61,7 +63,9 @@ - (void)viewDidLoad { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showFeaturedImageUploader:) name:@"UploadingFeaturedImage" object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(featuredImageUploadSucceeded:) name:FeaturedImageUploadSuccessful object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(featuredImageUploadFailed:) name:FeaturedImageUploadFailed object:nil]; - + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationWillChange:) name:UIApplicationWillChangeStatusBarOrientationNotification object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationDidChange:) name:UIApplicationDidChangeStatusBarOrientationNotification object:nil]; + [tableView setBackgroundView:nil]; [tableView setBackgroundColor:[UIColor clearColor]]; //Fix for black corners on iOS4. http://stackoverflow.com/questions/1557856/black-corners-on-uitableview-group-style self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"settings_bg"]]; @@ -111,12 +115,12 @@ - (void)viewDidLoad { [locationManager startUpdatingLocation]; } } - + featuredImageView.layer.shadowOffset = CGSizeMake(0.0, 1.0f); featuredImageView.layer.shadowColor = [[UIColor blackColor] CGColor]; featuredImageView.layer.shadowOpacity = 0.5f; featuredImageView.layer.shadowRadius = 1.0f; - + // Check if blog supports featured images id supportsFeaturedImages = [self.post.blog getOptionValue:@"post_thumbnail"]; if (supportsFeaturedImages != nil) { @@ -129,7 +133,7 @@ - (void)viewDidLoad { [featuredImageSpinner setHidden:NO]; if (!featuredImageSpinner.isAnimating) [featuredImageSpinner startAnimating]; - [tableView reloadData]; + [self reloadData]; [self.post getFeaturedImageURLWithSuccess:^{ if (self.post.featuredImageURL) { @@ -186,6 +190,10 @@ - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } +- (void)viewDidLayoutSubviews { + [featuredImageView orientationDidChange:nil]; +} + #pragma mark - #pragma mark Rotation Methods @@ -195,9 +203,18 @@ - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interface } - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { + [featuredImageView setupForOrientation:fromInterfaceOrientation]; [self reloadData]; } +- (void)orientationWillChange:(NSNotification *)notification { + [featuredImageView orientationWillChange:notification]; +} + +- (void)orientationDidChange:(NSNotification *)notification { + [featuredImageView orientationDidChange:notification]; + [self reloadData]; +} #pragma mark - #pragma mark Instance Methods @@ -220,7 +237,7 @@ - (void)loadFeaturedImage:(NSURL *)imageURL { [featuredImageSpinner stopAnimating]; [featuredImageSpinner setHidden:YES]; [featuredImageLabel setHidden:YES]; - + [self reloadData]; } failure:^(AFHTTPRequestOperation *operation, NSError *error) { // private blog, auth needed. if (operation.response.statusCode == 403) { @@ -282,7 +299,7 @@ - (void)endEditingForTextFieldAction:(id)sender { - (void)reloadData { passwordTextField.text = self.apost.password; - + [featuredImageView setBorderAndClipShowing:NO]; [tableView reloadData]; } @@ -610,10 +627,26 @@ - (UITableViewCell*) getGeolactionCellWithIndexPath: (NSIndexPath*)indexPath { return nil; } -- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { - if ((indexPath.section == 0) && (indexPath.row == 1) && (self.apost.password)) +- (CGFloat)tableView:(UITableView *)tblView heightForRowAtIndexPath:(NSIndexPath *)indexPath { + if ((indexPath.section == 0) && (indexPath.row == 1) && (self.apost.password)) { return 88.f; - else if ( + } else if (blogSupportsFeaturedImage && self.post.post_thumbnail && featuredImageView.image && indexPath.section == 2 && indexPath.row == 0) { + // find a suitable size for the featured image preview + CGRect topBounds = tblView.bounds; + CGFloat fillWidth = topBounds.size.width * 0.85f; + CGFloat fillHeight = featuredImageView.image.size.height / featuredImageView.image.size.width * fillWidth; + CGSize size = [UIScreen mainScreen].bounds.size; + UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; + if (UIInterfaceOrientationIsLandscape(orientation)) + { + size = CGSizeMake(size.height, size.width); + } + if (fillHeight > size.height * 0.85f) { + return size.height * 0.85f; + } else { + return fillHeight; + } + } else if ( (!blogSupportsFeaturedImage && (indexPath.section == 2) && (indexPath.row == 1)) || (blogSupportsFeaturedImage && (self.post.post_thumbnail || isUploadingFeaturedImage) && indexPath.section == 2 && indexPath.row == 0) || (blogSupportsFeaturedImage && (indexPath.section == 3) && (indexPath.row == 1)) @@ -683,7 +716,7 @@ - (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath break; case 1: actionSheet = [[UIActionSheet alloc] initWithTitle:NSLocalizedString(@"Remove this Featured Image?", @"Prompt when removing a featured image from a post") delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", "Cancel a prompt") destructiveButtonTitle:NSLocalizedString(@"Remove", @"Remove an image/posts/etc") otherButtonTitles:nil]; - [actionSheet showFromRect:cell.frame inView:postDetailViewController.view animated:YES]; + [actionSheet showFromRect:cell.frame inView:tableView animated:YES]; break; } } else { diff --git a/WordPress/Classes/QuickPhotoViewController.m b/WordPress/Classes/QuickPhotoViewController.m index 500aa680f629..51dcef032999 100644 --- a/WordPress/Classes/QuickPhotoViewController.m +++ b/WordPress/Classes/QuickPhotoViewController.m @@ -46,6 +46,7 @@ - (void)dealloc { [FileLogger log:@"%@ %@", self, NSStringFromSelector(_cmd)]; self.photoImageView.delegate = nil; self.popController.delegate = nil; + [[NSNotificationCenter defaultCenter] removeObserver:self]; } #if !__has_feature(objc_arc) @@ -96,6 +97,8 @@ - (void)viewDidLoad { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleKeyboardWillShow:) name:UIKeyboardWillShowNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleKeyboardWillHide:) name:UIKeyboardWillHideNotification object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationWillChange:) name:UIApplicationWillChangeStatusBarOrientationNotification object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationDidChange:) name:UIApplicationDidChangeStatusBarOrientationNotification object:nil]; } - (void)viewDidAppear:(BOOL)animated { @@ -143,7 +146,7 @@ - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interface - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration]; - + if (self.popController) { showPickerAfterRotation = YES; [popController dismissPopoverAnimated:NO]; @@ -153,13 +156,21 @@ - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrie - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { [super didRotateFromInterfaceOrientation:fromInterfaceOrientation]; - + if (showPickerAfterRotation) { showPickerAfterRotation = NO; [self showPicker]; } } +- (void)orientationWillChange:(NSNotification *)notification { + [photoImageView orientationWillChange:notification]; +} + +- (void)orientationDidChange:(NSNotification *)notification { + [photoImageView orientationDidChange:notification]; +} + #pragma mark - #pragma mark Custom methods @@ -323,6 +334,8 @@ - (void)imagePickerController:(UIImagePickerController *)picker didFinishPicking self.photo = (UIImage *)[info objectForKey:UIImagePickerControllerOriginalImage]; self.photoImageView.image = self.photo; + self.photoImageView.autoresizingMask = UIViewAutoresizingFlexibleWidth; + self.photoImageView.frame = CGRectMake(self.view.frame.size.width-150, 0, 150, 150); if (![self isViewLoaded]) { // If we get a memory warning on the way here our view could have unloaded. @@ -368,7 +381,6 @@ - (void)blogSelectorButtonDidBecomeInactive:(BlogSelectorButton *)button { - (void)pictureWillZoom { [self.titleTextField resignFirstResponder]; [self.contentTextView resignFirstResponder]; - [self.view bringSubviewToFront:photoImageView]; } - (void)pictureDidRestore { diff --git a/WordPress/Classes/QuickPicturePreviewView.h b/WordPress/Classes/QuickPicturePreviewView.h index 786097fa79fa..7d941a6a40ea 100644 --- a/WordPress/Classes/QuickPicturePreviewView.h +++ b/WordPress/Classes/QuickPicturePreviewView.h @@ -18,15 +18,25 @@ @end -@interface QuickPicturePreviewView : UIView { - UIImageView *imageView, *paperClipImageView; +@interface QuickPicturePreviewView : UIView { + UIView *backgroundView; + UIScrollView *scrollView; + UIImageView *imageView, *paperClipImageView, *zoomView; CALayer *frameLayer; BOOL zoomed; BOOL zooming; + BOOL hasBorderAndClip; CGRect normalFrame, normalImageFrame; + CGRect originalFrame; } @property (nonatomic, strong) UIImage *image; @property (nonatomic, weak) IBOutlet id delegate; +@property (nonatomic, assign) BOOL zoomed; + +- (void)setupForOrientation:(UIInterfaceOrientation)orientation; +- (void)setBorderAndClipShowing:(BOOL)visible; +- (void)orientationWillChange:(NSNotification *)note; +- (void)orientationDidChange:(NSNotification *)note; @end diff --git a/WordPress/Classes/QuickPicturePreviewView.m b/WordPress/Classes/QuickPicturePreviewView.m index dbbd2632997d..e0e139d9eef3 100644 --- a/WordPress/Classes/QuickPicturePreviewView.m +++ b/WordPress/Classes/QuickPicturePreviewView.m @@ -10,16 +10,70 @@ #define QPP_MARGIN 5.0f #define QPP_FRAME_WIDTH 5.0f #define QPP_SHADOW_SIZE 5.0f +#define MAX_ZOOM_SCALE 3.0f +#define ZOOM_ANIMATION_DURATION 0.3f @implementation QuickPicturePreviewView -@synthesize delegate; + +@synthesize delegate, zoomed; - (void)setupView { zoomed = NO; zooming = NO; + hasBorderAndClip = YES; + + backgroundView = [[UIView alloc] initWithFrame:self.frame]; + backgroundView.hidden = YES; + backgroundView.opaque = NO; + backgroundView.backgroundColor = [UIColor blackColor]; + backgroundView.alpha = 0.0f; + + scrollView = [[UIScrollView alloc] initWithFrame:self.frame]; + scrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; + scrollView.maximumZoomScale = MAX_ZOOM_SCALE; + scrollView.showsVerticalScrollIndicator = NO; + scrollView.showsHorizontalScrollIndicator = NO; + scrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite; + scrollView.delegate = self; + scrollView.hidden = YES; + scrollView.contentSize = CGSizeMake(1.f,1.f); + scrollView.scrollEnabled = NO; + scrollView.bounces = YES; + scrollView.backgroundColor = [UIColor clearColor]; + [self addSubview:scrollView]; + + UISwipeGestureRecognizer *swipeRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(zoomOut)]; + swipeRecognizer.direction = UISwipeGestureRecognizerDirectionUp | UISwipeGestureRecognizerDirectionDown; + [scrollView addGestureRecognizer:swipeRecognizer]; + + UITapGestureRecognizer *zoomOutRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(zoomOut)]; + zoomOutRecognizer.numberOfTapsRequired = 1; + [scrollView addGestureRecognizer:zoomOutRecognizer]; + + UITapGestureRecognizer *doubleTapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(zoomIn)]; + doubleTapRecognizer.numberOfTapsRequired = 2; + [scrollView addGestureRecognizer:doubleTapRecognizer]; + [zoomOutRecognizer requireGestureRecognizerToFail:doubleTapRecognizer]; + + zoomView = [[UIImageView alloc] init]; + zoomView.contentMode = UIViewContentModeScaleAspectFit; + zoomView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; + [scrollView addSubview:zoomView]; + imageView = [[UIImageView alloc] init]; imageView.contentMode = UIViewContentModeScaleAspectFit; [self addSubview:imageView]; + + UIInterfaceOrientation statusBarOrientation = [[UIApplication sharedApplication] statusBarOrientation]; + if (UIInterfaceOrientationIsLandscape(statusBarOrientation)) { + [self setupForOrientation:UIInterfaceOrientationPortraitUpsideDown]; + } else if (statusBarOrientation == UIInterfaceOrientationPortraitUpsideDown) { + [self setupForOrientation:UIInterfaceOrientationPortrait]; + } + + UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(zoomIn)]; + tapRecognizer.numberOfTapsRequired = 1; + [self addGestureRecognizer:tapRecognizer]; } - (id)init { @@ -38,43 +92,61 @@ - (id)initWithCoder:(NSCoder *)aDecoder { return self; } +- (id)initWithFrame:(CGRect)frame { + self = [super initWithFrame:frame]; + if (self) { + [self setupView]; + } + return self; +} + +- (void) setBorderAndClipShowing:(BOOL)visible { + hasBorderAndClip = visible; + [self layoutSubviews]; +} + - (void)layoutSubviews { UIImage *image = imageView.image; if (image != nil) { if (!zooming && !zoomed) { - CGSize imageSize = image.size; - CGFloat imageRatio = imageSize.width / imageSize.height; - CGSize frameSize = self.bounds.size; + CGFloat imageRatio = image.size.width / image.size.height; + CGSize frameSize = self.frame.size; + if (!hasBorderAndClip) + imageRatio = frameSize.width / frameSize.height; CGRect imageFrame; - + CGFloat width, height, maxsize; if (frameSize.width > frameSize.height) { - maxsize = frameSize.height; + maxsize = hasBorderAndClip ? frameSize.height : frameSize.width; } else { - maxsize = frameSize.width; + maxsize = hasBorderAndClip ? frameSize.width : frameSize.height; } if (imageRatio > 1) { - width = maxsize - 2.0f * (QPP_MARGIN + QPP_FRAME_WIDTH); + width = hasBorderAndClip ? maxsize - 2.0f * (QPP_MARGIN + QPP_FRAME_WIDTH) : maxsize; height = width / imageRatio; } else { - height = maxsize - 2.0f * (QPP_MARGIN + QPP_FRAME_WIDTH); + height = hasBorderAndClip ? maxsize - 2.0f * (QPP_MARGIN + QPP_FRAME_WIDTH) : maxsize; width = height * imageRatio; } - width += 5.0f; - height += 5.0f; + if (hasBorderAndClip) { + width += 5.0f; + height += 5.0f; + } - imageFrame = CGRectMake( - frameSize.width - width - (QPP_MARGIN + QPP_FRAME_WIDTH), - QPP_MARGIN + QPP_FRAME_WIDTH, - width, - height - ); + if (hasBorderAndClip) { + imageFrame = CGRectMake( + frameSize.width - width - (QPP_MARGIN + QPP_FRAME_WIDTH), + QPP_MARGIN + QPP_FRAME_WIDTH, + width, + height); + } else { + imageFrame = CGRectMake(0, 0, width, height); + } imageView.frame = imageFrame; if (frameLayer == nil) { frameLayer = [CALayer layer]; - frameLayer.backgroundColor = [UIColor whiteColor].CGColor; frameLayer.zPosition = -5; // Check for shadow compatibility (iOS 3.2+) if ([frameLayer respondsToSelector:@selector(setShadowColor:)]) { @@ -83,18 +155,25 @@ - (void)layoutSubviews { frameLayer.shadowOpacity = 0.5f; frameLayer.shadowRadius = 1.0f; } - [self.layer addSublayer:frameLayer]; + if (hasBorderAndClip) { + frameLayer.backgroundColor = [UIColor whiteColor].CGColor; + [self.layer addSublayer:frameLayer]; + } + } + if (hasBorderAndClip) { + imageFrame.size.width += 2 * QPP_FRAME_WIDTH; + imageFrame.size.height += 2 * QPP_FRAME_WIDTH; + imageFrame.origin.x -= QPP_FRAME_WIDTH; + imageFrame.origin.y -= QPP_FRAME_WIDTH; } - imageFrame.size.width += 2 * QPP_FRAME_WIDTH; - imageFrame.size.height += 2 * QPP_FRAME_WIDTH; - imageFrame.origin.x -= QPP_FRAME_WIDTH; - imageFrame.origin.y -= QPP_FRAME_WIDTH; frameLayer.frame = imageFrame; - paperClipImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"paperclip.png"]]; - paperClipImageView.frame = CGRectMake(3.0f, -8.0f, 15.0f, 41.0f); - [paperClipImageView setHidden:NO]; - [imageView addSubview:paperClipImageView]; + if (hasBorderAndClip) { + paperClipImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"paperclip.png"]]; + paperClipImageView.frame = CGRectMake(3.0f, -8.0f, 15.0f, 41.0f); + [paperClipImageView setHidden:NO]; + [imageView addSubview:paperClipImageView]; + } } } @@ -107,59 +186,238 @@ - (UIImage *)image { - (void)setImage:(UIImage *)image { [imageView setImage:image]; + [zoomView setImage:image]; [self setNeedsLayout]; } -- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context { - zooming = NO; - if (!zoomed) { - frameLayer.opacity = 1.0f; +- (void) zoomIn { + if (zoomed) { + if (scrollView.zoomScale <= 1.0f) + [scrollView setZoomScale:2.0f animated:YES]; + else + [scrollView setZoomScale:1.0f animated:YES]; + return; + } + + if (self.delegate && [self.delegate respondsToSelector:@selector(pictureWillZoom)]) { + [self.delegate pictureWillZoom]; + } + imageView.hidden = YES; + frameLayer.opacity = 0.0f; + zooming = YES; + + UIWindow *window = [[UIApplication sharedApplication] keyWindow]; + + scrollView.userInteractionEnabled = YES; + scrollView.scrollEnabled = YES; + scrollView.hidden = backgroundView.hidden = NO; + backgroundView.frame = [UIScreen mainScreen].bounds; + [window addSubview:backgroundView]; + + UIInterfaceOrientation current = [[UIApplication sharedApplication] statusBarOrientation]; + CGSize size = [UIScreen mainScreen].bounds.size; + if (UIInterfaceOrientationIsLandscape(current)) { + size = CGSizeMake(size.height, size.width); } + scrollView.contentSize = size; + if (hasBorderAndClip) { + scrollView.frame = [self convertRect:imageView.frame toView:window]; + } else { + scrollView.frame = [self convertRect:imageView.bounds toView:window]; + } + originalFrame = scrollView.frame; + zoomView.bounds = [self convertRect:imageView.bounds toView:scrollView]; + zoomView.frame = CGRectMake(0, 0, scrollView.bounds.size.width, scrollView.bounds.size.height); + [window addSubview:scrollView]; + [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent]; + + [UIView animateWithDuration:ZOOM_ANIMATION_DURATION + delay:0.0f + options:UIViewAnimationOptionCurveEaseInOut + animations:^{ + scrollView.frame = [UIScreen mainScreen].bounds; + backgroundView.alpha = 1.0f; + if (hasBorderAndClip) + paperClipImageView.alpha = 0.0f; + } completion:^(BOOL finished) { + zooming = NO; + zoomed = YES; + if (self.delegate && [self.delegate respondsToSelector:@selector(pictureDidZoom)]) + [self.delegate pictureDidZoom]; + }]; } -- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { - UITouch *touch = [touches anyObject]; - NSUInteger numTaps = [touch tapCount]; - - if (numTaps == 1) { - zooming = YES; - zoomed = ! zoomed; - if (zoomed) { - if (self.delegate && [self.delegate respondsToSelector:@selector(pictureWillZoom)]) { - [self.delegate pictureWillZoom]; - } - frameLayer.opacity = 0.0f; - } else { - if (self.delegate && [self.delegate respondsToSelector:@selector(pictureWillRestore)]) { - [self.delegate pictureWillRestore]; - } +- (void) zoomOut { + if (self.delegate && [self.delegate respondsToSelector:@selector(pictureWillRestore)]) { + [self.delegate pictureWillRestore]; + } + zooming = YES; + dispatch_async(dispatch_get_main_queue(), ^{ + double delayInSeconds = 0.0; + if (scrollView.zoomScale > 1) { + [scrollView setZoomScale:1.f animated:YES]; + delayInSeconds = 0.3; } - [UIView beginAnimations:@"zoom" context:nil]; - [UIView setAnimationDuration:0.3f]; - [UIView setAnimationDelegate:self]; - [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)]; + dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC)); + dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ + scrollView.userInteractionEnabled = NO; + scrollView.scrollEnabled = NO; + [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackOpaque]; + + [UIView animateWithDuration:ZOOM_ANIMATION_DURATION + delay:0.0f + options:UIViewAnimationOptionCurveEaseInOut + animations:^{ + scrollView.zoomScale = 1.0; + backgroundView.alpha = 0.0f; + scrollView.frame = originalFrame; + if (hasBorderAndClip) + paperClipImageView.alpha = 1.0f; + } completion:^(BOOL finished) { + [scrollView removeFromSuperview]; + [backgroundView removeFromSuperview]; + zooming = NO; + zoomed = NO; + imageView.hidden = NO; + frameLayer.opacity = 1.0f; + if (self.delegate && [self.delegate respondsToSelector:@selector(pictureDidRestore)]) + [self.delegate pictureDidRestore]; + }]; + }); + }); +} + +- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView { + return zoomView; +} + +- (void)scrollViewDidZoom:(UIScrollView *)_scrollView { + if (_scrollView.zoomScale > 1.f) { + _scrollView.scrollEnabled = YES; + } else { + _scrollView.scrollEnabled = NO; + } + + if (!_scrollView.zooming && _scrollView.zoomBouncing && _scrollView.zoomScale <= 1.f) { + dispatch_async(dispatch_get_main_queue(), ^{ + [self zoomOut]; + }); + } +} + +- (void) setupForOrientation:(UIInterfaceOrientation)orientation { + UIInterfaceOrientation current = [[UIApplication sharedApplication] statusBarOrientation]; + + CGFloat angle = 0.0; + switch (current) { + case UIInterfaceOrientationPortrait: { + switch (orientation) { + case UIInterfaceOrientationPortraitUpsideDown: + angle = (CGFloat)M_PI; + break; + + case UIInterfaceOrientationLandscapeLeft: + angle = (CGFloat)(M_PI*-90.0)/180.0; + break; + + case UIInterfaceOrientationLandscapeRight: + angle = (CGFloat)(M_PI*90.0)/180.0; + break; + + default: + return; + } + break; + } + + case UIInterfaceOrientationPortraitUpsideDown: { + switch (orientation) { + case UIInterfaceOrientationPortrait: + angle = (CGFloat)M_PI; + break; + + case UIInterfaceOrientationLandscapeLeft: + angle = (CGFloat)(M_PI*90.0)/180.0; + break; + + case UIInterfaceOrientationLandscapeRight: + angle = (CGFloat)(M_PI*-90.0)/180.0; + break; + + default: + return; + } + break; + } + + case UIInterfaceOrientationLandscapeLeft: { + switch (orientation) { + case UIInterfaceOrientationLandscapeRight: + angle = (CGFloat)M_PI; + break; + + case UIInterfaceOrientationPortraitUpsideDown: + angle = (CGFloat)(M_PI*-90.0)/180.0; + break; + + case UIInterfaceOrientationPortrait: + angle = (CGFloat)(M_PI*90.0)/180.0; + break; + + default: + return; + } + break; + } + + case UIInterfaceOrientationLandscapeRight: { + switch (orientation) { + case UIInterfaceOrientationLandscapeLeft: + angle = (CGFloat)M_PI; + break; + + case UIInterfaceOrientationPortrait: + angle = (CGFloat)(M_PI*-90.0)/180.0; + break; + + case UIInterfaceOrientationPortraitUpsideDown: + angle = (CGFloat)(M_PI*90.0)/180.0; + break; + + default: + return; + } + break; + } + } + + CGAffineTransform rotation = CGAffineTransformMakeRotation(angle); + + [UIView animateWithDuration:0.4 animations:^{ + scrollView.transform = CGAffineTransformConcat(rotation, scrollView.transform); + }]; +} + +- (void)orientationWillChange:(NSNotification *)note { + UIInterfaceOrientation orientation = [[[note userInfo] objectForKey: UIApplicationStatusBarOrientationUserInfoKey] integerValue]; + if (scrollView) { if (zoomed) { - normalFrame = self.frame; - normalImageFrame = imageView.frame; - self.frame = [self.superview bounds]; - self.backgroundColor = [UIColor blackColor]; - imageView.frame = self.frame; - paperClipImageView.alpha = 0.0f; - } else { - self.frame = normalFrame; - self.backgroundColor = [UIColor clearColor]; - imageView.frame = normalImageFrame; - paperClipImageView.alpha = 1.0f; + [scrollView setZoomScale:1.f animated:YES]; } - [UIView commitAnimations]; + [self setupForOrientation:orientation]; + } +} - if (zoomed) { - if (self.delegate && [self.delegate respondsToSelector:@selector(pictureDidZoom)]) - [self.delegate pictureDidZoom]; +- (void)orientationDidChange:(NSNotification *)note { + if (zoomed && scrollView) { + UIWindow *window = [[UIApplication sharedApplication] keyWindow]; + if (hasBorderAndClip) { + originalFrame = [self convertRect:imageView.frame toView:window]; } else { - if (self.delegate && [self.delegate respondsToSelector:@selector(pictureDidRestore)]) - [self.delegate pictureDidRestore]; + originalFrame = [self convertRect:self.bounds toView:window]; } + imageView.frame = self.bounds; + scrollView.frame = [UIScreen mainScreen].bounds; } } diff --git a/WordPress/Resources/PostSettingsViewController.xib b/WordPress/Resources/PostSettingsViewController.xib index 6c59d22f0a66..78d95d25c890 100644 --- a/WordPress/Resources/PostSettingsViewController.xib +++ b/WordPress/Resources/PostSettingsViewController.xib @@ -2,19 +2,18 @@ 784 - 12B19 - 2840 - 1187 - 624.00 + 12D78 + 3084 + 1187.37 + 626.00 com.apple.InterfaceBuilder.IBCocoaTouchPlugin - 1926 + 2083 IBMKMapView IBProxyObject IBUIActivityIndicatorView - IBUIImageView IBUILabel IBUITableView IBUITableViewCell @@ -47,7 +46,6 @@ {320, 372} - 3 MCAwAA @@ -154,7 +152,6 @@ {{94, 47}, {206, 31}} - NO YES IBCocoaTouchFramework @@ -242,7 +239,6 @@ {{130, 11}, {170, 21}} - NO YES 7 @@ -312,7 +308,6 @@ {{94, 11}, {206, 21}} - NO YES 7 @@ -380,7 +375,6 @@ {{116, 11}, {184, 21}} - NO YES 7 @@ -474,7 +468,6 @@ {{20, 155}, {280, 21}} - NO YES 7 @@ -526,16 +519,15 @@ 256 - + - 293 + 274 {{20, 13}, {280, 163}} - + _NS:9 1 - NO IBCocoaTouchFramework @@ -544,7 +536,6 @@ {{20, 96.5}, {280, 21}} - _NS:9 NO @@ -577,7 +568,7 @@ {{150, 71}, {20, 20}} - + _NS:9 NO IBCocoaTouchFramework @@ -592,7 +583,7 @@ {320, 187} - + _NS:11 NO @@ -793,9 +784,9 @@ featuredImageView - + - 274 + 276 @@ -963,9 +954,9 @@ 263 - + @@ -980,8 +971,8 @@ - 266 - + 275 + @@ -1010,7 +1001,8 @@ com.apple.InterfaceBuilder.IBCocoaTouchPlugin com.apple.InterfaceBuilder.IBCocoaTouchPlugin com.apple.InterfaceBuilder.IBCocoaTouchPlugin - com.apple.InterfaceBuilder.IBCocoaTouchPlugin + QuickPicturePreviewView + com.apple.InterfaceBuilder.IBCocoaTouchPlugin com.apple.InterfaceBuilder.IBCocoaTouchPlugin com.apple.InterfaceBuilder.IBCocoaTouchPlugin com.apple.InterfaceBuilder.IBCocoaTouchPlugin @@ -1019,7 +1011,7 @@ - 274 + 276 @@ -1032,7 +1024,7 @@ UILabel UIActivityIndicatorView UITableViewCell - UIImageView + QuickPicturePreviewView UITableViewCell MKMapView UITextField @@ -1073,7 +1065,7 @@ featuredImageView - UIImageView + QuickPicturePreviewView mapGeotagTableViewCell @@ -1145,6 +1137,25 @@ ./Classes/PostSettingsViewController.h + + QuickPicturePreviewView + UIView + + delegate + id + + + delegate + + delegate + id + + + + IBProjectSource + ./Classes/QuickPicturePreviewView.h + + 0 @@ -1155,10 +1166,10 @@ com.apple.InterfaceBuilder.CocoaTouchPlugin.iPhoneOS - + YES 3 - 1926 + 2083 diff --git a/WordPress/Resources/QuickPhotoViewController.xib b/WordPress/Resources/QuickPhotoViewController.xib index 1b6b77f5e49f..0e4ca6e28246 100644 --- a/WordPress/Resources/QuickPhotoViewController.xib +++ b/WordPress/Resources/QuickPhotoViewController.xib @@ -1,22 +1,22 @@ - 1296 - 11E53 - 2182 - 1138.47 - 569.00 + 1552 + 12D78 + 3084 + 1187.37 + 626.00 com.apple.InterfaceBuilder.IBCocoaTouchPlugin - 1181 + 2083 YES - IBUITextView + IBProxyObject IBUIImageView - IBUIView IBUITextField - IBProxyObject + IBUITextView + IBUIView YES @@ -46,7 +46,6 @@ 290 {{10, 5}, {180, 26}} - 3 @@ -88,7 +87,6 @@ 290 {{0, 39}, {190, 1}} - NO IBCocoaTouchFramework @@ -102,7 +100,6 @@ 274 {{0, 40}, {190, 308}} - NO @@ -129,7 +126,6 @@ 273 {{190, 0}, {130, 347}} - 3 @@ -142,7 +138,6 @@ 266 {{0, 355}, {320, 1}} - NO IBCocoaTouchFramework @@ -153,14 +148,12 @@ 266 {{0, 361}, {320, 50}} - IBCocoaTouchFramework {{0, 64}, {320, 416}} - 3 @@ -349,97 +342,12 @@ 28 - - - YES - - BlogSelectorButton - UIButton - - IBProjectSource - ./Classes/BlogSelectorButton.h - - - - QuickPhotoViewController - UIViewController - - YES - - YES - blogSelector - contentTextView - photoImageView - titleTextField - - - YES - BlogSelectorButton - UITextView - QuickPicturePreviewView - UITextField - - - - YES - - YES - blogSelector - contentTextView - photoImageView - titleTextField - - - YES - - blogSelector - BlogSelectorButton - - - contentTextView - UITextView - - - photoImageView - QuickPicturePreviewView - - - titleTextField - UITextField - - - - - IBProjectSource - ./Classes/QuickPhotoViewController.h - - - - QuickPicturePreviewView - UIView - - delegate - id - - - delegate - - delegate - id - - - - IBProjectSource - ./Classes/QuickPicturePreviewView.h - - - - + 0 IBCocoaTouchFramework com.apple.InterfaceBuilder.CocoaTouchPlugin.iPhoneOS - + com.apple.InterfaceBuilder.CocoaTouchPlugin.InterfaceBuilder3 @@ -451,6 +359,6 @@ table_sep.png {320, 1} - 1181 + 2083 diff --git a/WordPress/WordPress.xcodeproj/project.pbxproj b/WordPress/WordPress.xcodeproj/project.pbxproj index 158db8a7bbbd..8125620dd150 100644 --- a/WordPress/WordPress.xcodeproj/project.pbxproj +++ b/WordPress/WordPress.xcodeproj/project.pbxproj @@ -485,6 +485,7 @@ ACBAB6860E1247F700F38795 /* PostPreviewViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = ACBAB6850E1247F700F38795 /* PostPreviewViewController.m */; }; ACC156BB0E10D73100D6E1A0 /* EditPostViewController~iphone.xib in Resources */ = {isa = PBXBuildFile; fileRef = ACC156BA0E10D73100D6E1A0 /* EditPostViewController~iphone.xib */; }; ACC156CC0E10E67600D6E1A0 /* EditPostViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = ACC156CB0E10E67600D6E1A0 /* EditPostViewController.m */; }; + C2511EA4170A3D8C0081EC33 /* WordPressComApiCredentials.m in Sources */ = {isa = PBXBuildFile; fileRef = E1756DD51694560100D9EC00 /* WordPressComApiCredentials.m */; }; C533CF350E6D3ADA000C3DE8 /* CommentsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C533CF340E6D3ADA000C3DE8 /* CommentsViewController.m */; }; C55A90D90E8026CD00E1C9B5 /* WPSegmentedSelectionTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C55A90D80E8026CD00E1C9B5 /* WPSegmentedSelectionTableViewController.m */; }; C59D3D4B0E6410D300AA591D /* NSString+XMLExtensions.m in Sources */ = {isa = PBXBuildFile; fileRef = C59D3D4A0E6410D300AA591D /* NSString+XMLExtensions.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; @@ -596,7 +597,6 @@ E1745AA715AF4E5900A3F7C5 /* UIBarButtonItem+Styled.m in Sources */ = {isa = PBXBuildFile; fileRef = E1745AA615AF4E5900A3F7C5 /* UIBarButtonItem+Styled.m */; }; E174853016B028BF00D02746 /* keyboardButton@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = E1B62A8A13AAA96F00A6FCA4 /* keyboardButton@2x.png */; }; E174853116B028C300D02746 /* keyboardButton.png in Resources */ = {isa = PBXBuildFile; fileRef = E1B62A8813AAA5FE00A6FCA4 /* keyboardButton.png */; }; - E1756E651694A99400D9EC00 /* WordPressComApiCredentials.m in Sources */ = {isa = PBXBuildFile; fileRef = E1756E641694A99400D9EC00 /* WordPressComApiCredentials.m */; }; E177087913AAAD5800EA6C72 /* keyboardButton~ipad.png in Resources */ = {isa = PBXBuildFile; fileRef = E177087813AAAD5800EA6C72 /* keyboardButton~ipad.png */; }; E177087E13AAC19700EA6C72 /* redo~ipad.png in Resources */ = {isa = PBXBuildFile; fileRef = E177087A13AAC19700EA6C72 /* redo~ipad.png */; }; E177087F13AAC19700EA6C72 /* redoDisabled~ipad.png in Resources */ = {isa = PBXBuildFile; fileRef = E177087B13AAC19700EA6C72 /* redoDisabled~ipad.png */; }; @@ -3700,6 +3700,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + C2511EA4170A3D8C0081EC33 /* WordPressComApiCredentials.m in Sources */, 371C3682156CD12D007EA03E /* SectionInfo.m in Sources */, 371C3683156CD12D007EA03E /* SidebarSectionHeaderView.m in Sources */, 1D60589B0D05DD56006BFB54 /* main.m in Sources */, @@ -3817,7 +3818,6 @@ CC669B261672C335009E16F8 /* NoteCommentPostBanner.m in Sources */, 37B7924D16768FCC0021B3A4 /* NotificationSettingsViewController.m in Sources */, CC669B3A167AA82A009E16F8 /* NoteComment.m in Sources */, - E1756E651694A99400D9EC00 /* WordPressComApiCredentials.m in Sources */, 5DD91BC5163983670053E560 /* SoundUtil.m in Sources */, 5D4DE6F4167177560030518D /* WPInfoView.m in Sources */, CC5B0F23169B896300AA0291 /* NoteCommentLoadingCell.m in Sources */,