我的 iPad 应用程序的 UI 如下:
当我点击Settings按钮,我希望对话框水平翻转以显示设置对话框。
我这个工作正常。但是,当对话翻转时会显示背景颜色。如你看到的:
有什么办法可以让对话框翻转时不显示该颜色块吗?我希望它看起来更加无缝——就像一张纸翻过来一样。
观点基本上是这样的:
Window
主视图。设置为窗口的根视图控制器
登录模态视图
因此,主窗口和根控制器设置如下(在应用程序委托类中):
- (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;
}
登录窗口已设置并显示在主视图中查看是否出现:
- (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];
}
而当Settings按钮被按下:显示Settings模态视图的完成方式几乎与Login显示模态视图:
- (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];
}
我认为没有任何方法可以使用 modalPresentationStyle 来做你想做的事情。您需要使用以下方法使用过渡动画自行实现动画:
+ (void)transitionFromView:(UIView *)fromView toView:(UIView *)toView duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options completion:(void (^)(BOOL finished))completion
使用 UIViewAnimationOptionTransitionFlipFromLeft 选项。
在这种情况下,您想要翻转的新视图不是模态的内容(controller.view),而是模态框架本身,因此请尝试从设置按钮调用上面的方法,而不是传递controller.view,替换controller.view.superview,如果这不起作用,请尝试controller.view.superview.superview,直到动画看起来正确为止。
需要进行一些调整才能准确地确定如何做到这一点。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)