@@ -50,6 +50,11 @@ - (void)closePopupWithAnimation:(BOOL)animated
5050
5151 void (^finishCallback)(void ) = ^() {
5252 [self removeAllViewsFrom: self ->_popupGroup];
53+ UIWindow *mainWindow = [[UIApplication sharedApplication ] keyWindow ];
54+ UIView *mainView = mainWindow.subviews .lastObject ;
55+ [[UIApplication sharedApplication ] setAccessibilityElements: @[mainWindow, mainView]];
56+ mainWindow.isAccessibilityElement = NO ;
57+ mainView.isAccessibilityElement = NO ;
5358
5459 if (actionName) {
5560 if (track) {
@@ -73,6 +78,9 @@ - (void)closePopupWithAnimation:(BOOL)animated
7378 [[NSNotificationCenter defaultCenter ] removeObserver: self
7479 name: UIApplicationDidChangeStatusBarOrientationNotification
7580 object: nil ];
81+ [[NSNotificationCenter defaultCenter ] removeObserver: self
82+ name: UIApplicationDidBecomeActiveNotification
83+ object: nil ];
7684}
7785
7886// Displays the Center Popup, Interstitial and Web Interstitial.
@@ -87,15 +95,21 @@ - (void)showPopup
8795 }
8896 [self setupPopupView ];
8997 [self .popupGroup setAlpha: 0.0 ];
90- [[UIApplication sharedApplication ].keyWindow addSubview: self .popupGroup];
98+ [self addPopupGroupInKeyWindowAndSetupAccessibilityElement ];
99+
91100 [UIView animateWithDuration: LPMT_POPUP_ANIMATION_LENGTH animations: ^{
92- [self ->_popupGroup setAlpha: 0.5 ];
101+ [self ->_popupGroup setAlpha: 1.0 ];
93102 }];
94103
95104 [[NSNotificationCenter defaultCenter ] addObserver: self
96105 selector: @selector (orientationDidChange: )
97106 name: UIDeviceOrientationDidChangeNotification
98107 object: nil ];
108+
109+ [[NSNotificationCenter defaultCenter ] addObserver: self
110+ selector: @selector (appDidBecomeActive: )
111+ name: UIApplicationDidBecomeActiveNotification
112+ object: nil ];
99113}
100114
101115- (void )setupPopupView {
@@ -151,6 +165,31 @@ - (void)setupPopupView {
151165 [self updatePopupLayout ];
152166}
153167
168+ - (void )addPopupGroupInKeyWindowAndSetupAccessibilityElement {
169+ // set accessibility elemements for VoiceOver
170+ UIWindow *mainWindow = [[UIApplication sharedApplication ] keyWindow ];
171+ UIView *mainView = mainWindow.subviews .lastObject ;
172+ [mainWindow addSubview: self .popupGroup];
173+ [[UIApplication sharedApplication ] setAccessibilityElements: @[mainWindow, mainView, self .popupGroup]];
174+ mainWindow.isAccessibilityElement = YES ;
175+ mainView.isAccessibilityElement = YES ;
176+ self.popupGroup .isAccessibilityElement = NO ;
177+ [self setFocusForAccessibilityElement: _popupView];
178+ }
179+
180+ - (void )setFocusForAccessibilityElement : (UIView *)accessibleView {
181+ UIAccessibilityPostNotification (UIAccessibilityScreenChangedNotification,
182+ accessibleView);
183+ }
184+
185+ - (void )appDidBecomeActive : (NSNotification *)notification {
186+ if (self.popupGroup != nil ) {
187+ UIWindow *mainWindow = [[UIApplication sharedApplication ] keyWindow ];
188+ UIView *lastView = mainWindow.subviews .lastObject ;
189+ [self setFocusForAccessibilityElement: lastView];
190+ }
191+ }
192+
154193- (void )removeAllViewsFrom : (UIView *)view
155194{
156195 [view.subviews enumerateObjectsUsingBlock: ^(UIView *obj, NSUInteger idx, BOOL *stop) {
0 commit comments