我有一个UIViewControllerC,它是从另外两个UIViewcontroller
调用的ViewControllerA ViewControllerB
从ViewControllerA转到UIViewControllerC我必须使它成为presentviewcontroller
UIViewControllerC *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"UIViewControllerC"];
[vc setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
vc.tagfrom=@"present";
[self presentViewController:vc animated:NO completion:nil];
从ViewControllerB转到UIViewControllerC我必须使其推送视图
UIViewControllerC *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"UIViewControllerC"];
[vc setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
vc.tagfrom=@"push";
[self.navigationController pushViewController:vc animated:YES];
现在我必须从后退按钮的两个视图返回我检查tagfrom条件并处理它
-(IBAction)backBtn:(id)sender
{
if ([tagfrom isEqualToString:@"present"])
{
[self dismissViewControllerAnimated:NO completion:nil];
}
else
{
[self.navigationController popViewControllerAnimated:YES];
}
}
哪个在senerio中工作正常,但有时我的推送视图表现得像presentmodelveiw,并且没有过渡效果,请帮我解决
{{3}}
答案 0 :(得分:3)
首先,您的tagfrom
子类不需要UIViewController
属性。
UIViewController
个实例有一个名为presentingViewController
的属性,可让您了解当前{{1}的viewController
( A,在您的情况下) ( C在你的情况下)。
viewController
其次,-(IBAction)backBtn:(id)sender
{
if (nil != self.presentingViewController) {
[self dismissViewControllerAnimated:NO completion:nil];
}
else {
[self.navigationController popViewControllerAnimated:YES];
}
}
应该只与 modalTransitionStyle
和 NOT presentation
转换一起使用。如果您在push / pop
中使用此行为,则行为未定义,因为它不适合在那里使用。