-
Notifications
You must be signed in to change notification settings - Fork 0
/
GSImageViewPopup.m
76 lines (68 loc) · 2.47 KB
/
GSImageViewPopup.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//
// GSImageViewPopup.m
//
// Created by Ganpat on 16/07/18.
// Copyright © 2018 Ganpat Lakhara. All rights reserved.
//
#import "GSImageViewPopup.h"
@implementation GSImageViewPopup {
CGRect tempRect;
UIView *bgView;
BOOL animated;
double intDuration;
}
-(instancetype)initWithCoder:(NSCoder *)aDecoder {
self = [super initWithCoder:aDecoder];
animated = YES;
intDuration = 0.5;
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(popUpImageToFullScreen)];
[self addGestureRecognizer:tapGesture];
self.userInteractionEnabled = YES;
return self;
}
#pragma mark - Actions of Gestures
-(void)exitFullScreen {
UIImageView *imageV = bgView.subviews[0];
[UIView animateWithDuration:intDuration animations:^{
imageV.frame = tempRect;
bgView.alpha = 0;
} completion:^(BOOL finished) {
[bgView removeFromSuperview];
}];
}
-(void)popUpImageToFullScreen {
UIWindow *window = UIApplication.sharedApplication.delegate.window;
if (window != nil) {
UIView *parentView = [self findParentViewController:self].view;
bgView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
[bgView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(exitFullScreen)]];
bgView.alpha = 0;
bgView.backgroundColor = UIColor.blackColor;
UIImageView *imageV = [[UIImageView alloc] initWithImage:self.image];
CGRect rect = [self convertRect:self.bounds toView:parentView];
imageV.frame = rect;
tempRect = rect;
imageV.contentMode = UIViewContentModeScaleAspectFit;
[bgView addSubview:imageV];
[window addSubview:bgView];
if (animated) {
[UIView animateWithDuration:intDuration animations:^{
bgView.alpha = 1;
imageV.frame = CGRectMake(0, 0, parentView.frame.size.width, parentView.frame.size.width);
imageV.center = parentView.center;
}];
}
}
}
-(UIViewController*)findParentViewController:(UIView*)view {
UIResponder *parentResponder = self;
while (parentResponder != nil) {
parentResponder = parentResponder.nextResponder;
if ([parentResponder isKindOfClass:[UIViewController class]]) {
UIViewController *viewController = (UIViewController*)parentResponder;
return viewController;
}
}
return nil;
}
@end