From fed09bfc3640b423f65c73e74697646433d37b02 Mon Sep 17 00:00:00 2001 From: Jordan Morgan Date: Fri, 20 Nov 2015 16:23:27 -0600 Subject: [PATCH] Changed modal presentation style Also added some test code to display and image and 3D touch --- .../BFRImageViewController.m | 1 + .../BFRImageViewer/Base.lproj/Main.storyboard | 39 ++++++----------- .../BFRImageViewer/FirstViewController.m | 42 +++++++++++++++++-- 3 files changed, 52 insertions(+), 30 deletions(-) diff --git a/BFRImageViewController/BFRImageViewController.m b/BFRImageViewController/BFRImageViewController.m index ca42298..53b008a 100644 --- a/BFRImageViewController/BFRImageViewController.m +++ b/BFRImageViewController/BFRImageViewController.m @@ -31,6 +31,7 @@ - (instancetype)initWithImageSource:(NSArray *)images { if (self) { NSAssert(images.count > 0, @"You must supply at least one image source to use this class."); self.images = images; + self.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; } return self; diff --git a/BFRImageViewerDemo/BFRImageViewer/Base.lproj/Main.storyboard b/BFRImageViewerDemo/BFRImageViewer/Base.lproj/Main.storyboard index 5258761..b511ad0 100644 --- a/BFRImageViewerDemo/BFRImageViewer/Base.lproj/Main.storyboard +++ b/BFRImageViewerDemo/BFRImageViewer/Base.lproj/Main.storyboard @@ -1,13 +1,14 @@ - + - + + - + @@ -15,28 +16,8 @@ - - - - + - - - - - - @@ -47,7 +28,7 @@ - + @@ -58,18 +39,21 @@ + @@ -92,6 +76,7 @@ + diff --git a/BFRImageViewerDemo/BFRImageViewer/FirstViewController.m b/BFRImageViewerDemo/BFRImageViewer/FirstViewController.m index d7f27e8..0042100 100644 --- a/BFRImageViewerDemo/BFRImageViewer/FirstViewController.m +++ b/BFRImageViewerDemo/BFRImageViewer/FirstViewController.m @@ -7,9 +7,10 @@ // #import "FirstViewController.h" +#import "BFRImageViewController.h" -@interface FirstViewController () - +@interface FirstViewController () +@property (strong, nonatomic) NSURL *imgURL; @end @implementation FirstViewController @@ -17,11 +18,46 @@ @implementation FirstViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. + UIButton *openImageFromURL = [UIButton buttonWithType:UIButtonTypeRoundedRect]; + openImageFromURL.translatesAutoresizingMaskIntoConstraints = NO; + [openImageFromURL setTitle:@"Open Image" forState:UIControlStateNormal]; + [openImageFromURL addTarget:self action:@selector(openImage) forControlEvents:UIControlEventTouchUpInside]; + [self.view addSubview:openImageFromURL]; + [openImageFromURL.centerXAnchor constraintEqualToAnchor:self.view.centerXAnchor].active = YES; + [openImageFromURL.centerYAnchor constraintEqualToAnchor:self.view.centerYAnchor].active = YES; + + if ([self.traitCollection respondsToSelector:@selector(forceTouchCapability)] && self.traitCollection.forceTouchCapability == UIForceTouchCapabilityAvailable) { + [self check3DTouch]; + } + + self.imgURL = [NSURL URLWithString:@"https://pmcvariety.files.wordpress.com/2014/04/36820.jpg?w=670&h=377&crop=1"]; } - (void)didReceiveMemoryWarning { - [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } +- (void)openImage { + BFRImageViewController *imageVC = [[BFRImageViewController alloc] initWithImageSource:@[self.imgURL]]; + [self presentViewController:imageVC animated:YES completion:nil]; +} + +#pragma mark - 3D Touch +- (void)check3DTouch { + [self registerForPreviewingWithDelegate:self sourceView:self.view]; +} + +- (UIViewController *)previewingContext:(id)previewingContext viewControllerForLocation:(CGPoint)location { + return [[BFRImageViewController alloc] initWithImageSource:@[self.imgURL]]; +} + +- (void)previewingContext:(id)previewingContext commitViewController:(UIViewController *)viewControllerToCommit { + [self presentViewController:viewControllerToCommit animated:YES completion:nil]; +} + +- (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection { + if ([self.traitCollection respondsToSelector:@selector(forceTouchCapability)] && self.traitCollection.forceTouchCapability == UIForceTouchCapabilityAvailable) { + [self check3DTouch]; + } +} @end