8000 Fix wrong hide animations · netgit/SCLAlertView@8297931 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8297931

Browse files
committed
Fix wrong hide animations
1 parent ec283d8 commit 8297931

File tree

1 file changed

+31
-46
lines changed

1 file changed

+31
-46
lines changed

SCLAlertView/SCLAlertView.m

Lines changed: 31 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -254,23 +254,23 @@ - (void)setupViewWindowWidth:(CGFloat)windowWidth
254254
_contentView.layer.borderColor = UIColorFromHEX(0xCCCCCC).CGColor; //Light Grey
255255
}
256256

257-
- (void)setupNewWindow
258-
{
257+
- (void)setupNewWindow {
258+
// Save previous window
259+
self.previousWindow = [UIApplication sharedApplication].keyWindow;
260+
259261
// Create a new one to show the alert
260262
UIWindow *alertWindow = [[UIWindow alloc] initWithFrame:[self mainScreenFrame]];
261263
alertWindow.windowLevel = UIWindowLevelAlert;
262264
alertWindow.backgroundColor = [UIColor clearColor];
263-
alertWindow.rootViewController = self;
265+
alertWindow.rootViewController = [UIViewController new];
264266
alertWindow.accessibilityViewIsModal = YES;
265267
self.SCLAlertWindow = alertWindow;
266-
267268
self.usingNewWindow = YES;
268269
}
269270

270271
#pragma mark - Modal Validation
271272

272-
- (BOOL)isModal
273-
{
273+
- (BOOL)isModal {
274274
return (_rootViewController != nil && _rootViewController.presentingViewController);
275275
}
276276

@@ -295,50 +295,43 @@ - (void)viewWillLayoutSubviews
295295
// Reposition inner circle appropriately
296296
CGFloat x = (kCircleHeightBackground - kCircleHeight) / 2;
297297
_circleView.frame = CGRectMake(x, x, kCircleHeight, kCircleHeight);
298-
if (_labelTitle.text == nil)
299-
{
298+
if (_labelTitle.text == nil) {
300299
kTitleTop = kCircleHeightBackground / 2;
301300
}
302301
} else {
303302
kCircleBackgroundTopPosition = -(kCircleHeightBackground / 2);
304303
}
305304

306305
// 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) {
309307
sz = _rootViewController.view.frame.size;
310308
}
311309

312-
if (SYSTEM_VERSION_LESS_THAN(@"8.0"))
313-
{
310+
if (SYSTEM_VERSION_LESS_THAN(@"8.0")) {
314311
// 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)) {
317313
CGSize ssz = sz;
318314
sz = CGSizeMake(ssz.height, ssz.width);
319315
}
320316
}
321317

322-
// Set new background frame
323-
CGRect newBackgroundFrame = self.backgroundView.frame;
324-
newBackgroundFrame.size = sz;
325-
self.backgroundView.frame = newBackgroundFrame;
326-
327318
// Set new main frame
328319
CGRect r;
329-
if (self.view.superview != nil)
330-
{
320+
if (self.view.superview != nil) {
331321
// View is showing, position at center of screen
332322
r = CGRectMake((sz.width-_windowWidth)/2, (sz.height-_windowHeight)/2, _windowWidth, _windowHeight);
333-
}
334-
else
335-
{
323+
} else {
336324
// View is not visible, position outside screen bounds
337325
r = CGRectMake((sz.width-_windowWidth)/2, -_windowHeight, _windowWidth, _windowHeight);
338326
}
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;
339333

340334
// Set frames
341-
self.view.frame = r;
342335
_contentView.frame = CGRectMake(0.0f, 0.0f, _windowWidth, _windowHeight);
343336
_circleViewBackground.frame = CGRectMake(_windowWidth / 2 - kCircleHeightBackground / 2, kCircleBackgroundTopPosition, kCircleHeightBackground, kCircleHeightBackground);
344337
_circleViewBackground.layer.cornerRadius = _circleViewBackground.frame.size.height / 2;
@@ -355,24 +348,21 @@ - (void)viewWillLayoutSubviews
355348
}
356349

357350
y += _subTitleHeight + 14.0f;
358-
for (SCLTextView *textField in _inputs)
359-
{
351+
for (SCLTextView *textField in _inputs) {
360352
textField.frame = CGRectMake(12.0f, y, _windowWidth - 24.0f, textField.frame.size.height);
361353
textField.layer.cornerRadius = 3.0f;
362354
y += textField.frame.size.height + 10.0f;
363355
}
364356

365357
// Custom views
366-
for (UIView *view in _customViews)
367-
{
358+
for (UIView *view in _customViews) {
368359
view.frame = CGRectMake(12.0f, y, view.frame.size.width, view.frame.size.height);
369360
y += view.frame.size.height + 10.0f;
370361
}
371362

372363
// Buttons
373364
CGFloat x = 12.0f;
374-
for (SCLButton *btn in _buttons)
375-
{
365+
for (SCLButton *btn in _buttons) {
376366
btn.frame = CGRectMake(x, y, btn.frame.size.width, btn.frame.size.height);
377367

378368
// Add horizontal or vertical offset acording on _horizontalButtons parameter
@@ -802,17 +792,15 @@ - (void)addTimerToButtonIndex:(NSInteger)buttonIndex reverse:(BOOL)reverse
802792

803793
- (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
804794
{
805-
if(_usingNewWindow)
806-
{
807-
// Save previous window
808-
self.previousWindow = [UIApplication sharedApplication].keyWindow;
795+
if(_usingNewWindow) {
796+
809797
self.backgroundView.frame = _SCLAlertWindow.bounds;
810798

811799
// 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 {
816804
_rootViewController = vc;
817805

818806
[self disableInteractivePopGesture];
@@ -1361,17 +1349,14 @@ - (void)fadeOutWithDuration:(NSTimeInterval)duration
13611349
self.view.alpha = 0.0f;
13621350
} completion:^(BOOL completed) {
13631351
[self.backgroundView removeFromSuperview];
1364-
if (_usingNewWindow)
1365-
{
1352+
[self.view removeFromSuperview];
1353+
[self removeFromParentViewController];
1354+
1355+
if (_usingNewWindow) {
13661356
// Remove current window
13671357
[self.SCLAlertWindow setHidden:YES];
13681358
self.SCLAlertWindow = nil;
13691359
}
1370-
else
1371-
{
1372-
[self.view removeFromSuperview];
1373-
[self removeFromParentViewController];
1374-
}
13751360
if ( _dismissAnimationCompletionBlock ){
13761361
self.dismissAnimationCompletionBlock();
13771362
}

0 commit comments

Comments
 (0)
0