我正在展示带动画的模型视图.默认情况下,它来自自下而上.如何让动画从左到右?我知道我可以使用导航控制器.但实际上,呈现视图不需要导航栏,并且模态呈现的视图也不需要导航栏.我仍然希望从左到右过渡.
modal-dialog modalviewcontroller presentmodalviewcontroller ios
我有一个视图控制器,上面有一个按钮.该按钮是隐私政策.当它被点击时,它会转到正确的IBAction,我创建了隐私控制器.
- IBAction ...
{
PrivacyPolicyViewController *privacy = [[PrivacyPolicyViewController alloc] init];
.....
}
Run Code Online (Sandbox Code Playgroud)
我想创建一个隐私控制器的模态视图,它有一个向上动画的UIWebView和一个用于在ios 7中关闭它的后退按钮.我在网上看到的所有方式都是ios 6并且似乎已被弃用.
我有一些代码要清理viewWillDisappear:,我只想在视图移回父视图控制器时使用.
- (void)viewWillDisappear:(BOOL)animated
{
if ([self isMovingFromParentViewController] || [self isBeingDismissed]) {
NSLog(@"isMovingFromParentViewController or isBeingDismissed");
// clean up
}
[super viewWillDisappear:animated];
}
Run Code Online (Sandbox Code Playgroud)
视图可以以两种方式呈现:它可以由导航控制器推动,或者呈现为模态视图控制器(来自相同的导航控制器).如果它被按下,然后弹出(按下后退按钮),我的清理代码就会运行.如果它呈现为模态视图控制器,然后被解雇,则代码不会运行.
我这样解雇:
[rootViewController dismissModalViewControllerAnimated:YES];
Run Code Online (Sandbox Code Playgroud)
我的问题是:isBeingDismissed当我解雇我的视图控制器时为什么没有设置?
所以我有一个模态视图,并希望以编程方式添加UINavigationBar并使用Done按钮在用户完成阅读内容时关闭此视图.
有关如何执行此操作的任何想法以及是否可以完全不使用界面构建器?
将数据从子模态视图传递到父视图控制器的最佳方法是什么?
我的iPad应用程序上有一个子模态登录屏幕,我想将用户信息传递给父拆分视图控制器.
我正在考虑使用NSNotification,但我不确定这是否是将数据传递回父级的最简单/最有效的方法.
谢谢!艾伦
我有两个视图需要以模态方式显示,一个接一个.如果我们连续解雇和显示,这不起作用,如下所示:
[rootController dismissModalViewControllerAnimated: YES];
[rootController presentModalViewController: psvc animated: YES];
Run Code Online (Sandbox Code Playgroud)
第二个模态视图根本没有显示出来.
我见过一个像这样的修复:
[rootController dismissModalViewControllerAnimated: YES];
[[UIApplication sharedApplication] beginIgnoringInteractionEvents];
[self performSelector: @selector(seekModal) withObject: nil afterDelay: 0.5];
[[UIApplication sharedApplication] endIgnoringInteractionEvents];
Run Code Online (Sandbox Code Playgroud)
问题是这不会一直有效(所需的延迟有时是优越的).
另一个可能的解决方法是消除动画:
[rootController dismissModalViewControllerAnimated: NO];
[rootController presentModalViewController: psvc animated: YES];
Run Code Online (Sandbox Code Playgroud)
但我真的很想保留动画,以保持第一个模态不受影响的感觉.有什么建议?
我有一个作为ModelViewController呈现的登录视图,我有一个注册视图,在其上面显示为NavigationControlloer:
登录(ModelViewController)---->注册(NavigationController)
我在Loginview上展示了Register视图(CreateAccount),如下所示:
createAccount= [[CreateAccount alloc] initWithNibName:@"CreateAccount" bundle:nil];
navController = [[UINavigationController alloc] initWithRootViewController:createAccount];
UIBarButtonItem *cancelButtun=[[UIBarButtonItem alloc]initWithTitle:@"Cancel" style:UIBarButtonItemStyleBordered target:self action:@selector(HideMe)];
UIBarButtonItem *registerButtun=[[UIBarButtonItem alloc]initWithTitle:@"Register" style:UIBarButtonItemStyleBordered target:self action:@selector(Register)];
createAccount.navigationItem.leftBarButtonItem = cancelButtun;
createAccount.navigationItem.rightBarButtonItem=registerButtun;
createAccount.title=@"Create Account";
[self presentModalViewController:navController animated:YES];
Run Code Online (Sandbox Code Playgroud)
登录控制器具有NSURLConnectionDelegate用于booth登录和注册.注册完成后我只需拨打电话
[self dismissModalViewControllerAnimated:YES];
Run Code Online (Sandbox Code Playgroud)
这将仅取消注册视图.
我想解雇登录视图,所以我可以回到我的主应用程序.
这是我的视图(控制器)层次结构:
UITabBarController(作为rootViewController应用程序)UINavigationController(作为viewController其中一个tabBar标签)UIViewController(作为rootViewController的UINavigationController)UICollectionView (作为子视图)MyViewController.view(作为节的标题视图UICollectionView)所以,我需要提供一个模态视图控制器MyViewController.我试过这样做
[self presentViewController:modalVC animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)
尽管它有效,Xcode警告我"不鼓励在分离的视图控制器上呈现视图控制器",这是正确的,因为modalVC只填充集合视图标题的视图,这不是我所追求的全屏.
我尝试过的所有其他选项:
UITabBarController *tb = (UITabBarController *)self.view.window.rootViewController;
[tb presentViewController:modalVC animated:YES completion:nil];
or...
UINavigationController *nc = (UINavigationController *)tb.selectedViewController;
[tb presentViewController:modalVC animated:YES completion:nil];
or...
UICustomViewController *cv = (UICustomViewController *)nc.topViewController;
[vc presentViewController:modalVC animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)
然而,当我通过调用关闭modalVC时,根据需要呈现modalVC全屏
[self dismissViewControllerAnimated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)
从modalVC本身来看,modalVC确实解散了自己,但我留下了黑屏.一点调试显示,在解雇modalVC之后,self.view.window.rootViewController变成了nil.
知道为什么会这样,以及如何解决这个问题?
编辑
这是一款iPhone应用程序.iOS7和iOS8都有黑屏.另外,下面是我发起的方法MyViewController
#pragma mark - UICollectionViewDelegate …Run Code Online (Sandbox Code Playgroud) 首先,我创建一个MainViewController.然后在MainViewController中,我这样做
[self presentViewController:modalViewController animated:YES completion:nil];
modalViewController.modalPresentationStyle = UIModalPresentationFormSheet;
Run Code Online (Sandbox Code Playgroud)
当我关闭modalViewController时,On iPhone(iPhone 6+除外),调用MainViewController的viewDidAppear.在iPad和iPhone 6+上,不调用MainViewController的viewDidAppear.
逻辑是在解除modalViewController时调用一个函数.我如何知道modalViewController何时被解除.
我一直在努力寻找这个问题的答案.我通过以下方式构建了一堆模态:
[[[NavA viewControllers] objectAtIndex:0] presentViewController:NavB animated:YES completion:NULL];
[[[NavB viewControllers] objectAtIndex:0] presentViewController:NavC animated:YES completion:NULL];
Run Code Online (Sandbox Code Playgroud)
当我想同时解雇NavA和NavB模态时,我打电话给
[[[NavA viewControllers] objectAtIndex:0] dismissViewControllerAnimated:YES completion:NULL];
Run Code Online (Sandbox Code Playgroud)
这样可以正常工作,除了有一个简短的闪存,你可以看到NavB,因为完整的堆栈被解雇了.
我走过了调试器,看起来在动画开始之前,NavC立即消失,NavB用动画解散.
有没有办法避免这种视觉神器,并且整个堆栈在动画的整个持续时间内可以使NavC平滑地消失?
编辑:为了澄清,我提出的UINavigationController不是UIViewController因为这个流程是供用户登录的,而且有多个可能的分支可以返回到当前阶段,例如NavC(LoginPage),NavB(带登录和注册按钮的LandingPage)或所有返回根目录,NavA(应用程序的主页面).在iOS文档中,它们呈现了与相机类似的设计模式,其中每个舞台呈现UINavigationController多个可能的视图控制器https://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/ModalViewControllers/ModalViewControllers.html
ios ×8
objective-c ×6
iphone ×5
xcode ×3
animated ×1
cocoa-touch ×1
dismiss ×1
ios7 ×1
modal-dialog ×1
uiwebview ×1