forked from organicmaps/organicmaps
[ios] Added fade in/out to dialogs.
This commit is contained in:
parent
585fc97d9a
commit
3f7f1874bf
3 changed files with 41 additions and 18 deletions
|
@ -12,11 +12,13 @@
|
|||
#include "routing/router.hpp"
|
||||
#include "storage/storage.hpp"
|
||||
|
||||
typedef void (^CloseAlertCompletion)();
|
||||
|
||||
@interface MWMAlertViewController : UIViewController
|
||||
|
||||
@property (weak, nonatomic, readonly) UIViewController * ownerViewController;
|
||||
@property (nonnull, weak, nonatomic, readonly) UIViewController * ownerViewController;
|
||||
|
||||
- (instancetype)initWithViewController:(UIViewController *)viewController;
|
||||
- (nonnull instancetype)initWithViewController:(nonnull UIViewController *)viewController;
|
||||
- (void)presentAlert:(routing::IRouter::ResultCode)type;
|
||||
- (void)presentDownloaderAlertWithCountries:(vector<storage::TIndex> const &)countries routes:(vector<storage::TIndex> const &)routes;
|
||||
- (void)presentCrossCountryAlertWithCountries:(vector<storage::TIndex> const &)countries routes:(vector<storage::TIndex> const &)routes;
|
||||
|
@ -28,12 +30,11 @@
|
|||
- (void)presentLocationAlert;
|
||||
- (void)presentLocationServiceNotSupportedAlert;
|
||||
- (void)presentNoConnectionAlert;
|
||||
- (void)presentnoWiFiAlertWithName:(NSString *)name downloadBlock:(RightButtonAction)block;
|
||||
- (void)presentnoWiFiAlertWithName:(nonnull NSString *)name downloadBlock:(nullable RightButtonAction)block;
|
||||
- (void)closeAlertWithCompletion:(nullable CloseAlertCompletion)completion;
|
||||
|
||||
- (void)closeAlert;
|
||||
|
||||
- (instancetype)init __attribute__((unavailable("-init isn't available, call -initWithViewController: instead!")));
|
||||
+ (instancetype)new __attribute__((unavailable("+new isn't available, call -initWithViewController: instead!")));
|
||||
- (instancetype)initWithCoder:(NSCoder *)aDecoder __attribute__((unavailable("-initWithCoder: isn't available, call -initWithViewController: instead!")));
|
||||
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil __attribute__((unavailable("-initWithNibName:bundle: isn't available, call -initWithViewController: instead!")));
|
||||
- (nonnull instancetype)init __attribute__((unavailable("-init isn't available, call -initWithViewController: instead!")));
|
||||
+ (nonnull instancetype)new __attribute__((unavailable("+new isn't available, call -initWithViewController: instead!")));
|
||||
- (nonnull instancetype)initWithCoder:(nonnull NSCoder *)aDecoder __attribute__((unavailable("-initWithCoder: isn't available, call -initWithViewController: instead!")));
|
||||
- (nonnull instancetype)initWithNibName:(nullable NSString *)nibNameOrNil bundle:(nullable NSBundle *)nibBundleOrNil __attribute__((unavailable("-initWithNibName:bundle: isn't available, call -initWithViewController: instead!")));
|
||||
@end
|
||||
|
|
|
@ -15,13 +15,13 @@ static NSString * const kAlertControllerNibIdentifier = @"MWMAlertViewController
|
|||
|
||||
@interface MWMAlertViewController () <UIGestureRecognizerDelegate, UIAlertViewDelegate>
|
||||
|
||||
@property (weak, nonatomic, readwrite) UIViewController * ownerViewController;
|
||||
@property (nonnull ,weak, nonatomic, readwrite) UIViewController * ownerViewController;
|
||||
|
||||
@end
|
||||
|
||||
@implementation MWMAlertViewController
|
||||
|
||||
- (instancetype)initWithViewController:(UIViewController *)viewController
|
||||
- (nonnull instancetype)initWithViewController:(nonnull UIViewController *)viewController
|
||||
{
|
||||
self = [super initWithNibName:kAlertControllerNibIdentifier bundle:nil];
|
||||
if (self)
|
||||
|
@ -86,7 +86,7 @@ static NSString * const kAlertControllerNibIdentifier = @"MWMAlertViewController
|
|||
[self displayAlert:MWMAlert.noConnectionAlert];
|
||||
}
|
||||
|
||||
- (void)presentnoWiFiAlertWithName:(NSString *)name downloadBlock:(RightButtonAction)block
|
||||
- (void)presentnoWiFiAlertWithName:(nonnull NSString *)name downloadBlock:(nullable RightButtonAction)block
|
||||
{
|
||||
[self displayAlert:[MWMAlert noWiFiAlertWithName:name downloadBlock:block]];
|
||||
}
|
||||
|
@ -125,6 +125,10 @@ static NSString * const kAlertControllerNibIdentifier = @"MWMAlertViewController
|
|||
{
|
||||
alert.alertController = self;
|
||||
[self.ownerViewController addChildViewController:self];
|
||||
self.view.alpha = 0.;
|
||||
alert.alpha = 0.;
|
||||
CGFloat const scale = 1.1;
|
||||
alert.transform = CGAffineTransformMakeScale(scale, scale);
|
||||
self.view.center = self.ownerViewController.view.center;
|
||||
[self.ownerViewController.view addSubview:self.view];
|
||||
UIWindow * window = [[[UIApplication sharedApplication] delegate] window];
|
||||
|
@ -133,13 +137,29 @@ static NSString * const kAlertControllerNibIdentifier = @"MWMAlertViewController
|
|||
[self.view addSubview:alert];
|
||||
alert.bounds = self.view.bounds;
|
||||
alert.center = self.view.center;
|
||||
[UIView animateWithDuration:.15 animations:^
|
||||
{
|
||||
self.view.alpha = 1.;
|
||||
alert.alpha = 1.;
|
||||
alert.transform = CGAffineTransformIdentity;
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)closeAlert
|
||||
- (void)closeAlertWithCompletion:(nullable CloseAlertCompletion)completion
|
||||
{
|
||||
self.ownerViewController.view.userInteractionEnabled = YES;
|
||||
[self.view removeFromSuperview];
|
||||
[self removeFromParentViewController];
|
||||
MWMAlert * alert = self.view.subviews.firstObject;
|
||||
[UIView animateWithDuration:.15 animations:^
|
||||
{
|
||||
alert.alpha = 0.;
|
||||
self.view.alpha = 0.;
|
||||
}
|
||||
completion:^(BOOL finished)
|
||||
{
|
||||
if (completion)
|
||||
completion();
|
||||
[self.view removeFromSuperview];
|
||||
[self removeFromParentViewController];
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)openSettings
|
||||
|
|
|
@ -105,8 +105,10 @@
|
|||
|
||||
- (void)close
|
||||
{
|
||||
[self removeFromSuperview];
|
||||
[self.alertController closeAlert];
|
||||
[self.alertController closeAlertWithCompletion:^
|
||||
{
|
||||
[self removeFromSuperview];
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)setNeedsCloseAlertAfterEnterBackground
|
||||
|
|
Loading…
Add table
Reference in a new issue