@@ -254,23 +254,23 @@ - (void)setupViewWindowWidth:(CGFloat)windowWidth
254
254
_contentView.layer .borderColor = UIColorFromHEX (0xCCCCCC ).CGColor ; // Light Grey
255
255
}
256
256
257
- - (void )setupNewWindow
258
- {
257
+ - (void )setupNewWindow {
258
+ // Save previous window
259
+ self.previousWindow = [UIApplication sharedApplication ].keyWindow ;
260
+
259
261
// Create a new one to show the alert
260
262
UIWindow *alertWindow = [[UIWindow alloc ] initWithFrame: [self mainScreenFrame ]];
261
263
alertWindow.windowLevel = UIWindowLevelAlert;
262
264
alertWindow.backgroundColor = [UIColor clearColor ];
263
- alertWindow.rootViewController = self ;
265
+ alertWindow.rootViewController = [UIViewController new ] ;
264
266
alertWindow.accessibilityViewIsModal = YES ;
265
267
self.SCLAlertWindow = alertWindow;
266
-
267
268
self.usingNewWindow = YES ;
268
269
}
269
270
270
271
#pragma mark - Modal Validation
271
272
272
- - (BOOL )isModal
273
- {
273
+ - (BOOL )isModal {
274
274
return (_rootViewController != nil && _rootViewController.presentingViewController );
275
275
}
276
276
@@ -295,50 +295,43 @@ - (void)viewWillLayoutSubviews
295
295
// Reposition inner circle appropriately
296
296
CGFloat x = (kCircleHeightBackground - kCircleHeight ) / 2 ;
297
297
_circleView.frame = CGRectMake (x, x, kCircleHeight , kCircleHeight );
298
- if (_labelTitle.text == nil )
299
- {
298
+ if (_labelTitle.text == nil ) {
300
299
kTitleTop = kCircleHeightBackground / 2 ;
301
300
}
302
301
} else {
303
302
kCircleBackgroundTopPosition = -(kCircleHeightBackground / 2 );
304
303
}
305
304
306
305
// Check if the rootViewController is modal, if so we need to get the modal size not the main screen size
307
- if ([self isModal ] && !_usingNewWindow)
308
- {
306
+ if ([self isModal ] && !_usingNewWindow) {
309
307
sz = _rootViewController.view .frame .size ;
310
308
}
311
309
312
- if (SYSTEM_VERSION_LESS_THAN (@" 8.0" ))
313
- {
310
+ if (SYSTEM_VERSION_LESS_THAN (@" 8.0" )) {
314
311
// iOS versions before 7.0 did not switch the width and height on device roration
315
- if (UIInterfaceOrientationIsLandscape ([UIApplication sharedApplication ].statusBarOrientation ))
316
- {
312
+ if (UIInterfaceOrientationIsLandscape ([UIApplication sharedApplication ].statusBarOrientation )) {
317
313
CGSize ssz = sz;
318
314
sz = CGSizeMake (ssz.height , ssz.width );
319
315
}
320
316
}
321
317
322
- // Set new background frame
323
- CGRect newBackgroundFrame = self.backgroundView .frame ;
324
- newBackgroundFrame.size = sz;
325
- self.backgroundView .frame = newBackgroundFrame;
326
-
327
318
// Set new main frame
328
319
CGRect r;
329
- if (self.view .superview != nil )
330
- {
320
+ if (self.view .superview != nil ) {
331
321
// View is showing, position at center of screen
332
322
r = CGRectMake ((sz.width -_windowWidth)/2 , (sz.height -_windowHeight)/2 , _windowWidth, _windowHeight);
333
- }
334
- else
335
- {
323
+ } else {
336
324
// View is not visible, position outside screen bounds
337
325
r = CGRectMake ((sz.width -_windowWidth)/2 , -_windowHeight, _windowWidth, _windowHeight);
338
326
}
327
+ self.view .frame = r;
328
+
329
+ // Set new background frame
330
+ CGRect newBackgroundFrame = self.backgroundView .frame ;
331
+ newBackgroundFrame.size = sz;
332
+ self.backgroundView .frame = newBackgroundFrame;
339
333
340
334
// Set frames
341
- self.view .frame = r;
342
335
_contentView.frame = CGRectMake (0 .0f , 0 .0f , _windowWidth, _windowHeight);
343
336
_circleViewBackground.frame = CGRectMake (_windowWidth / 2 - kCircleHeightBackground / 2 , kCircleBackgroundTopPosition , kCircleHeightBackground , kCircleHeightBackground );
344
337
_circleViewBackground.layer .cornerRadius = _circleViewBackground.frame .size .height / 2 ;
@@ -355,24 +348,21 @@ - (void)viewWillLayoutSubviews
355
348
}
356
349
357
350
y += _subTitleHeight + 14 .0f ;
358
- for (SCLTextView *textField in _inputs)
359
- {
351
+ for (SCLTextView *textField in _inputs) {
360
352
textField.frame = CGRectMake (12 .0f , y, _windowWidth - 24 .0f , textField.frame .size .height );
361
353
textField.layer .cornerRadius = 3 .0f ;
362
354
y += textField.frame .size .height + 10 .0f ;
363
355
}
364
356
365
357
// Custom views
366
- for (UIView *view in _customViews)
367
- {
358
+ for (UIView *view in _customViews) {
368
359
view.frame = CGRectMake (12 .0f , y, view.frame .size .width , view.frame .size .height );
369
360
y += view.frame .size .height + 10 .0f ;
370
361
}
371
362
372
363
// Buttons
373
364
CGFloat x = 12 .0f ;
374
- for (SCLButton *btn in _buttons)
375
- {
365
+ for (SCLButton *btn in _buttons) {
376
366
btn.frame = CGRectMake (x, y, btn.frame .size .width , btn.frame .size .height );
377
367
378
368
// Add horizontal or vertical offset acording on _horizontalButtons parameter
@@ -802,17 +792,15 @@ - (void)addTimerToButtonIndex:(NSInteger)buttonIndex reverse:(BOOL)reverse
802
792
803
793
- (SCLAlertViewResponder *)showTitle : (UIViewController *)vc image : (UIImage *)image color : (UIColor *)color title : (NSString *)title subTitle : (NSString *)subTitle duration : (NSTimeInterval )duration completeText : (NSString *)completeText style : (SCLAlertViewStyle)style
804
794
{
805
- if (_usingNewWindow)
806
- {
807
- // Save previous window
808
- self.previousWindow = [UIApplication sharedApplication ].keyWindow ;
795
+ if (_usingNewWindow) {
796
+
809
797
self.backgroundView .frame = _SCLAlertWindow.bounds ;
810
798
811
799
// Add window subview
812
- [_SCLAlertWindow addSubview: _backgroundView ];
813
- }
814
- else
815
- {
800
+ [_SCLAlertWindow.rootViewController addChildViewController: self ];
801
+ [_SCLAlertWindow.rootViewController.view addSubview: _backgroundView];
802
+ [_SCLAlertWindow.rootViewController.view addSubview: self .view];
803
+ } else {
816
804
_rootViewController = vc;
817
805
818
806
[self disableInteractivePopGesture ];
@@ -1361,17 +1349,14 @@ - (void)fadeOutWithDuration:(NSTimeInterval)duration
1361
1349
self.view .alpha = 0 .0f ;
1362
1350
} completion: ^(BOOL completed) {
1363
1351
[self .backgroundView removeFromSuperview ];
1364
- if (_usingNewWindow)
1365
- {
1352
+ [self .view removeFromSuperview ];
1353
+ [self removeFromParentViewController ];
1354
+
1355
+ if (_usingNewWindow) {
1366
1356
// Remove current window
1367
1357
[self .SCLAlertWindow setHidden: YES ];
1368
1358
self.SCLAlertWindow = nil ;
1369
1359
}
1370
- else
1371
- {
1372
- [self .view removeFromSuperview ];
1373
- [self removeFromParentViewController ];
1374
- }
1375
1360
if ( _dismissAnimationCompletionBlock ){
1376
1361
self.dismissAnimationCompletionBlock ();
1377
1362
}
0 commit comments