我正在尝试构建我的自定义 segue,其行为类似于标准 Push segue,但在我的情况下,我想使用自定义按钮在屏幕之间切换(没有标签栏适合这个应用程序,任何模式 segue 也不好) . 主屏幕是自定义图形,而要切换到的屏幕是地图。用户选择地图上的点,点击完成并返回主屏幕及其坐标。我正在尝试将 ViewControllers 与自定义 segue 连接起来。
我在 Internet 上研究了很多解决方案,找到了一个适合的解决方案,但是代码分散在 ViewControllers 和 AppDelegate 周围(我不确定 Apple 是否会接受它)。我正在尝试将整个代码放入 CustomSegue.m /h。成功是部分的,因为使用技术(如下)它与第二个 ViewControler 相匹配,但我不知道如何关闭第二个并返回主屏幕。我尝试了各种技术,但是当我运行它时,编译器会以一堆错误终止应用程序。在构建和运行之前既没有错误也没有警告。我还尝试使用 [selfdismissModalViewControllerAnimated:YES] 使用按钮将其关闭;或 [self dismissViewControllerAnimated:YES 完成:nil];当我尝试模态序列但我的代码结果不佳时,它们会起作用。
有没有人对这样做的巧妙方法提出建议。在过去的几天里,我一直在解决这个问题。我在很多应用程序中看到了这种转场,所以它似乎很流行,简单的解决方案。我对 Xcode 的经验并不多,只有几个 mo。这是我的自定义 segue(带有 QuartzCore 动画)。
#import "CustomTabBarSegue.h"
@implementation CustomTabBarSegue
-(void)perform {
UIViewController *src = (UIViewController*)[self sourceViewController];
UIViewController *dst = (UIViewController*)[self destinationViewController];
UIView *currentView = src.view;
UIView *theWindow = [currentView superview];
UIView *newView = dst.view;
[theWindow addSubview:newView];
CATransition *transition = [CATransition animation];
transition.delegate = self;
transition.duration = 1;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionMoveIn;
transition.subtype = kCATransitionFromRight;
[[theWindow layer] addAnimation:transition forKey:@"MySegue"];
}
@end
下面是我的按钮从destinationVC返回的代码。(不起作用)
- (IBAction)dismiss:(id)sender
{
[self dismissViewControllerAnimated:YES completion:^() {
[self performSegueWithIdentifier:@"MySegue" sender:self];
}];
}