Подтвердить что ты не робот

Модальный стиль перехода, например, в приложении Mail

Я пытаюсь добиться эффекта модального представления, когда представленное представление охватывает родительский вид только частично, как показано на рисунке ниже.

enter image description here

Я знаю, что смог бы достичь этого, выполнив пользовательские переходы с помощью UIPresentationController. Я не хочу изобретать колесо, поэтому, прежде чем я начну с разработки, я бы хотел спросить.

Есть ли поддержка для поддержки такого перехода в API?

Я изучил все доступные Модальные стили презентации, и мне кажется, что нет поддержки для перехода, который я хочу сделать, и единственный способ его достижения - просто code it.

4b9b3361

Ответ 1

Я столкнулся с этой же проблемой. Я также пошел по стилю стилей модальной презентации и продолжал нажимать на стену (особенно, чтобы заставить ее работать на iPhone, а не на iPad).

После некоторого копания я смог заставить его работать. Вот как я это сделал:

Чтобы начать, нам нужен контроллер представления, который мы будем представлять (модальный), чтобы установить его прозрачный цвет фона и установить кадр представления контроллера навигации на некоторое смещение.

ModalViewController.h

@import UIKit;

@class ModalViewController;

@protocol ModalViewControllerDelegate <NSObject>

- (void)modalViewControllerDidCancel:(ModalViewController *)modalViewController;

@end

@interface ModalViewController : UIViewController
@property (weak, nonatomic) id<ModalViewControllerDelegate> delegate;

- (instancetype)initWithRootViewController:(UIViewController *)rootViewController;
@end

ModalViewController.m

static const CGFloat kTopOffset = 50.0f;

@implementation ModalViewController {
    UINavigationController *_navController;
}

- (instancetype)initWithRootViewController:(UIViewController *)rootViewController
{
    self = [super initWithNibName:nil bundle:nil];
    if (self) {
        rootViewController.navigationItem.leftBarButtonItem = [self cancelButton];
        _navController = [[UINavigationController alloc] initWithRootViewController:rootViewController];
        self.view.backgroundColor = [UIColor clearColor];
        [self.view addSubview:_navController.view];

        // this is important (prevents black overlay)
        self.modalPresentationStyle = UIModalPresentationOverFullScreen;
    }

    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    CGRect bounds = self.view.bounds;
    _navController.view.frame = CGRectMake(0, kTopOffset, CGRectGetWidth(bounds), CGRectGetHeight(bounds) - kTopOffset);
}

- (UIBarButtonItem *)cancelButton
{
    return [[UIBarButtonItem alloc] initWithTitle:@"Cancel" style:UIBarButtonItemStylePlain target:self action:@selector(cancelButtonClicked:)];
}

- (void)cancelButtonClicked:(id)sender
{
    [_delegate modalViewControllerDidCancel:self];
}

@end

Затем нам нужно настроить контроллер представления для запуска следующей анимации:

  • Уменьшить масштаб
  • Угадайте бит lil '
  • Представьте контроллер модального представления, используя presentViewController:animated:completion

Это то, что я сделал

PresentingViewController.m

static const CGFloat kTransitionScale = 0.9f;
static const CGFloat kTransitionAlpha = 0.6f;
static const NSTimeInterval kTransitionDuration = 0.5;

@interface PresentingViewController <ModalViewControllerDelegate>
@end

@implementation PresentingViewController
...
...

- (void)showModalViewController
{
    self.navigationController.view.layer.shouldRasterize = YES;
    self.navigationController.view.layer.rasterizationScale = [UIScreen mainScreen].scale;

    UIViewController *controller = // init some view controller
    ModalViewController *container = [[ModalViewController alloc] initWithRootViewController:controller];
    container.delegate = self;

    __weak UIViewController *weakSelf = self;
    [UIView animateWithDuration:kTransitionDuration animations:^{
        weakSelf.navigationController.view.transform = CGAffineTransformMakeScale(kTransitionScale, kTransitionScale);
        weakSelf.navigationController.view.alpha = kTransitionAlpha;
        [weakSelf presentViewController:container animated:YES completion:nil];
    } completion:^(BOOL finished) {
        weakSelf.navigationController.view.layer.shouldRasterize = NO;
    }];
}

#pragma mark - ModalViewControllerDelegate

- (void)modalViewControllerDidCancel:(ModalViewController *)modalViewController
{
    __weak UIViewController *weakSelf = self;
    [UIView animateWithDuration:kTransitionDuration animations:^{
        weakSelf.navigationController.view.alpha = 1;
        weakSelf.navigationController.view.transform = CGAffineTransformIdentity;
        [weakSelf dismissViewControllerAnimated:YES completion:nil];
    }];
}
@end

Ответ 2

уверен, что это сделано как

let newVC = <view controller you want to display>
let nav: UINavigationController = UINavigationController(rootViewController: newVC)
if let currVc = UIApplication.sharedApplication().keyWindow?.rootViewController {
    nav.transitioningDelegate = currVc
    nav.modalPresentationStyle = UIModalPresentationStyle.Custom;
    currVc.presentViewController(nav, animated: true, completion: nil)
}