gpt4 book ai didi

没有导航 Controller 的 ios segues

转载 作者:可可西里 更新时间:2023-11-01 04:27:31 27 4
gpt4 key购买 nike

我想使用 Storyboard来创建我的应用程序。我可以找到很多关于如何将它与导航或选项卡 Controller 一起使用的信息,但我不想使用它们中的任何一个。

我的目标是创建一个具有不同 View 但不使用导航或选项卡 Controller 的应用程序。我该怎么做?

最佳答案

在IOS storyboard中,如果你不想使用navigation,那么你就不能使用push segue。然后,您可以使用模态转场或自定义转场。在 modal segue 中,有四种转换:

  1. 垂直覆盖
  2. 水平翻转
  3. 交叉融合
  4. 部分 curl

但是,所有这些预定义的转场动画都不能预制水平滑动动画转场。如果你想使用水平滑动效果,你必须使用自定义segue。您需要像这样重写该函数:

- (void) perform
{
UIViewController *desViewController = (UIViewController *)self.destinationViewController;

UIView *srcView = [(UIViewController *)self.sourceViewController view];
UIView *desView = [desViewController view];

desView.transform = srcView.transform;
desView.bounds = srcView.bounds;

if(isLandscapeOrientation)
{
if(isDismiss)
{
desView.center = CGPointMake(srcView.center.x, srcView.center.y - srcView.frame.size.height);
}
else
{
desView.center = CGPointMake(srcView.center.x, srcView.center.y + srcView.frame.size.height);
}
}
else
{
if(isDismiss)
{
desView.center = CGPointMake(srcView.center.x - srcView.frame.size.width, srcView.center.y);
}
else
{
desView.center = CGPointMake(srcView.center.x + srcView.frame.size.width, srcView.center.y);
}
}


UIWindow *mainWindow = [[UIApplication sharedApplication].windows objectAtIndex:0];
[mainWindow addSubview:desView];

// slide newView over oldView, then remove oldView
[UIView animateWithDuration:0.3
animations:^{
desView.center = CGPointMake(srcView.center.x, srcView.center.y);

if(isLandscapeOrientation)
{
if(isDismiss)
{
srcView.center = CGPointMake(srcView.center.x, srcView.center.y + srcView.frame.size.height);
}
else
{
srcView.center = CGPointMake(srcView.center.x, srcView.center.y - srcView.frame.size.height);
}
}
else
{
if(isDismiss)
{
srcView.center = CGPointMake(srcView.center.x + srcView.frame.size.width, srcView.center.y);
}
else
{
srcView.center = CGPointMake(srcView.center.x - srcView.frame.size.width, srcView.center.y);
}
}
}
completion:^(BOOL finished){
//[desView removeFromSuperview];
[self.sourceViewController presentModalViewController:desViewController animated:NO];
}];
}

如果还有问题,可以查看这篇文章。它还有一个 youtube 视频向您展示如何实现此自定义转场:

Create Push Segue Animation Without UINavigation Controller

关于没有导航 Controller 的 ios segues,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12278845/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com