Presenting a modal view controller over only one half of a split view controller

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-06 14:37:50

问题


I'm adapting an existing iPhone app to run on the iPad. In the iPhone version, when the user tapped a toolbar button, I would present a modal view controller with a modalTransitionStyle of UIModalTransitionStyleFlipHorizontal, which made a really nice "card-flipping" animation.

The iPad interface is based on a split view (MGSplitViewController, actually). The toolbar button is on the detail pane, so when I present the modal view controller, it takes up the entire screen and the flip transition makes no sense.

To get the right user interaction, I'd like the modal controller to appear and flip into place only over the detail view controller, leaving the master view controller as is.

Is there any way to do this?


回答1:


UIViewController *viewController = [[UIViewController alloc] init];
viewController.modalPresentationStyle = UIModalPresentationCurrentContext;

[self presentViewController:viewController animated:YES completion:nil];



回答2:


Probably you can just add its view as as a subview of DetailViewcontroller and use UIview animation to make it look like modal. Reference to [UIView transitionFromView:toView:duration:options:completion]

EDIT When watching WWDC2010 Video (Session 123 : Building Animation Driven Interfaces), I accidentally came to know that I can do the same transition in different manner. I sample coded and it worked :)

It is to use another very similar API [UIView transitionWithView:duration:options:animations:completion:]

My sample code is as follows

// Within your DetailViewController
[self.view addSubview:self.flipSideView];
[UIView transitionWithView:self.view duration:0.8 options:UIViewAnimationOptionTransitionFlipFromLeft animations:^{} completion:nil];

Yup, that was it. Just add the flip side view as a subview and use transitionWithView:... animation instead of transitionFromView....



来源:https://stackoverflow.com/questions/12762899/presenting-a-modal-view-controller-over-only-one-half-of-a-split-view-controller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!