从一个模式视图无缝翻转到另一个,没有显示纯色背景 [英] Seamlessly flip from one modal view to another, without showing a solid colour background

查看:221
本文介绍了从一个模式视图无缝翻转到另一个,没有显示纯色背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个iPad应用程式的下列使用者介面:





当我点击设置按钮时,我想让对话框水平翻转显示设置对话框。 p>

我有这个工作正常。但是,当dailog翻转时,会显示一个背景颜色。如您所见:





有没有什么办法不能有这个颜色的块是可见的,因为对话框翻转?



视图本质上是这样的:


窗口


主视图。设置到窗口的 rootViewController


登录模式视图




因此,主窗口和根控制器设置如下(在app委托类中):

   - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.viewController = [[MainViewController alloc] initWithNibName:@MainViewbundle:nil];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}

登录窗口设置并显示在主视图的 viewDidAppear

   - (void)viewDidAppear:(BOOL)animated 
{
[super viewDidAppear :animated];

//设置并显示登录对话框
LoginViewController * controller = [[LoginViewController alloc] initWithNibName:@LoginViewbundle:nil];
controller.delegate = self;
controller.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
controller.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentModalViewController:controller animated:YES];
}

当按下设置 模式视图的显示方式与 模式视图相同:

   - (IBAction)settingsButtonPressed:(id)sender {
SettingsViewController * controller = [[SettingsViewController alloc] initWithNibName:@SettingsViewbundle:nil];
controller.delegate = self;
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizo​​ntal;
controller.modalPresentationStyle = UIModalPresentationCurrentContext;
[self presentModalViewController:controller animated:YES];
}


解决方案

任何方式做你想要使用modalPresentationStyle。您需要使用以下方法使用过渡动画自己实现动画:

  +(void)transitionFromView: *)fromView toView:(UIView *)toView duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options completion:(void(^)(BOOL finished))completion 

使用UIViewAnimationOptionTransitionFlipFromLeft选项。



在这种情况下,您要翻转的新视图不是modal(controller.view)而是模态框架本身,所以实验只是从你的设置按钮调用上面的方法,而不是传递controller.view,替换controller.view.superview,如果这不工作,试试



这将需要一些调整来确定如何做。


I have the following UI for an iPad app:

When I click on the Settings button, I want the dialog to horizontally flip to show the settings dialog.

I have this working fine. But, there is a background colour shown when the dailog flips over. As you can see:

Is there any way to not have this block of colour be visible as the dialogs flip? I'd like it to look more seamless -- as if it's a sheet of paper flipping over.

The views are essentially this:

Window

Main View. Set to the window's rootViewController

Login modal view

Thus the main window and root controller are setup as follows (in the app delegate class):

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.viewController = [[MainViewController alloc] initWithNibName:@"MainView" bundle:nil];
    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];
    return YES;
}

The login window is setup and shown in the main view's viewDidAppear:

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];

    // Setup and show Login dialog
    LoginViewController* controller = [[LoginViewController alloc] initWithNibName:@"LoginView" bundle:nil];
    controller.delegate = self;
    controller.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
    controller.modalPresentationStyle = UIModalPresentationFormSheet;
   [self presentModalViewController:controller animated:YES];
}

And when the Settings button is pressed: showing the Settings modal view is done in pretty much the same way that the Login modal view was shown:

- (IBAction)settingsButtonPressed:(id)sender {
    SettingsViewController *controller = [[SettingsViewController alloc] initWithNibName:@"SettingsView" bundle:nil];
    controller.delegate = self;
    controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    controller.modalPresentationStyle = UIModalPresentationCurrentContext;
    [self presentModalViewController:controller animated:YES];    
}

解决方案

I don't think there's any way to do what you want using the modalPresentationStyle. You'll need to implement the animation yourself using a transition animation using the following method:

+ (void)transitionFromView:(UIView *)fromView toView:(UIView *)toView duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options completion:(void (^)(BOOL finished))completion

With the UIViewAnimationOptionTransitionFlipFromLeft option.

In this case the new view you want to flip is not the content of the modal (the controller.view) but the modal frame itself, so experiment with just calling the method above from your settings button, and instead of passing controller.view, substitute controller.view.superview, and if that doesn't work, try controller.view.superview.superview until the animation looks right.

It will require some tweaking to work out exactly how to do it.

这篇关于从一个模式视图无缝翻转到另一个,没有显示纯色背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆